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 
33 #ifndef vtkOpenGLContextDevice2D_h
34 #define vtkOpenGLContextDevice2D_h
35 
36 #include "vtkContextDevice2D.h"
37 #include "vtkRenderingContextOpenGL2Module.h" // For export macro
38 
39 #include <list> // for std::list
40 #include <vector> // STL Header
41 
42 class vtkMatrix4x4;
43 class vtkOpenGLExtensionManager;
44 class vtkOpenGLHelper;
46 class vtkPath;
47 class vtkRenderer;
48 class vtkShaderProgram;
49 class vtkStringToImage;
50 class vtkTransform;
51 class vtkViewport;
52 class vtkWindow;
53 
54 class VTKRENDERINGCONTEXTOPENGL2_EXPORT vtkOpenGLContextDevice2D : public vtkContextDevice2D
55 {
56 public:
58  void PrintSelf(ostream& os, vtkIndent indent) override;
59 
64 
70  void DrawPoly(float* f, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
71 
78  void DrawLines(float* f, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
79 
85  void DrawPoints(float* points, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
86 
93  void DrawPointSprites(vtkImageData* sprite, float* points, int n, unsigned char* colors = nullptr,
94  int nc_comps = 0) override;
95 
111  void DrawMarkers(int shape, bool highlight, float* points, int n, unsigned char* colors = nullptr,
112  int nc_comps = 0) override;
113 
115 
120  vtkSetMacro(MaximumMarkerCacheSize, int);
121  vtkGetMacro(MaximumMarkerCacheSize, int);
123 
127  void DrawQuad(float* points, int n) override;
128 
132  void DrawQuadStrip(float* points, int n) override;
133 
137  void DrawPolygon(float*, int) override;
139  float* points, int numPoints, unsigned char* colors = nullptr, int nc_comps = 0) override;
140 
152  void DrawEllipseWedge(float x, float y, float outRx, float outRy, float inRx, float inRy,
153  float startAngle, float stopAngle) override;
154 
162  float x, float y, float rX, float rY, float startAngle, float stopAngle) override;
163 
167  void DrawString(float* point, const vtkStdString& string) override;
168 
177  void ComputeStringBounds(const vtkStdString& string, float bounds[4]) override;
178 
184  void ComputeJustifiedStringBounds(const char* string, float bounds[4]) override;
185 
190  void DrawMathTextString(float point[2], const vtkStdString& string) override;
191 
196  void DrawImage(float p[2], float scale, vtkImageData* image) override;
197 
203  void DrawImage(const vtkRectf& pos, vtkImageData* image) override;
204 
209  void DrawPolyData(float p[2], float scale, vtkPolyData* polyData, vtkUnsignedCharArray* colors,
210  int scalarMode) override;
211 
215  void SetColor4(unsigned char color[4]) override;
216 
220  virtual void SetColor(unsigned char color[3]);
221 
225  void SetTexture(vtkImageData* image, int properties = 0) override;
226 
230  void SetPointSize(float size) override;
231 
235  void SetLineWidth(float width) override;
236 
240  void SetLineType(int type) override;
241 
245  void MultiplyMatrix(vtkMatrix3x3* m) override;
246 
250  void SetMatrix(vtkMatrix3x3* m) override;
251 
255  void GetMatrix(vtkMatrix3x3* m) override;
256 
260  void PushMatrix() override;
261 
265  void PopMatrix() override;
266 
267  /*
268  * Supply an int array of length 4 with x1, y1, width, height specifying
269  * clipping region for the device in pixels.
270  */
271  void SetClipping(int* x) override;
272 
276  void EnableClipping(bool enable) override;
277 
281  void Begin(vtkViewport* viewport) override;
282 
286  void End() override;
287 
296 
304  void BufferIdModeEnd() override;
305 
312 
318 
322  bool HasGLSL();
323 
325 
328  vtkGetObjectMacro(RenderWindow, vtkOpenGLRenderWindow);
330 
336  virtual void ReleaseGraphicsResources(vtkWindow* window);
337 
339 
345 
346 protected:
349 
357  int GetNumberOfArcIterations(float rX, float rY, float startAngle, float stopAngle);
358 
363 
367  bool InRender;
368 
370 
373  class Private;
375 
376  class CellArrayHelper;
379 
384 
385  vtkOpenGLHelper* LinesCBO; // vertex + color
389  vtkOpenGLHelper* VCBO; // vertex + color
391  vtkOpenGLHelper* VBO; // vertex
393  vtkOpenGLHelper* VTBO; // vertex + tcoord
395  vtkOpenGLHelper* SCBO; // sprite + color
397  vtkOpenGLHelper* SBO; // sprite
399 
401  void BuildVBO(
402  vtkOpenGLHelper* cbo, float* v, int nv, unsigned char* coolors, int nc, float* tcoords);
404  std::vector<float>& tverts, unsigned char* colors = nullptr, int numComp = 0);
405  // used for stipples
406  unsigned short LinePattern;
407 
409 
414  int shape, bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
416  bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
418  bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
420  bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
422  bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
424  bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
426 
428 
431  void DrawImageGL2PS(float p[2], vtkImageData* image);
432  void DrawImageGL2PS(float p[2], float scale, vtkImageData* image);
435 
437 
440  void DrawCircleGL2PS(float x, float y, float rX, float rY);
441  void DrawWedgeGL2PS(float x, float y, float outRx, float outRy, float inRx, float inRy);
443 
447  void AddEllipseToPath(vtkPath* path, float x, float y, float rx, float ry, bool reverse);
448 
452  void TransformPath(vtkPath* path) const;
453 
457  void TransformPoint(float& x, float& y) const;
458 
462  void TransformSize(float& dx, float& dy) const;
463 
464 private:
466  void operator=(const vtkOpenGLContextDevice2D&) = delete;
467 
474  vtkImageData* GetMarker(int shape, int size, bool highlight);
475 
476  class vtkMarkerCacheObject
477  {
478  public:
479  vtkTypeUInt64 Key;
480  vtkImageData* Value;
481  bool operator==(vtkTypeUInt64 key) { return this->Key == key; }
482  };
483 
484  void ComputeStringBoundsInternal(const std::string& string, float bounds[4]);
485 
486  vtkTransform* ProjectionMatrix;
487  vtkTransform* ModelMatrix;
488 
489  std::list<vtkMarkerCacheObject> MarkerCache;
490  int MaximumMarkerCacheSize;
491 
496  vtkImageData* GenerateMarker(int shape, int size, bool highlight);
497 };
498 
499 #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:63
a simple class to control print indentation
Definition: vtkIndent.h:49
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:46
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:51
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:45
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:100
abstract specification for renderers
Definition: vtkRenderer.h:82
The ShaderProgram uses one or more Shader objects.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:48
base class for classes that render supplied text to an image.
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:70
dynamic, self-adjusting array of unsigned char
abstract specification for Viewports
Definition: vtkViewport.h:65
window superclass for vtkRenderWindow
Definition: vtkWindow.h:48
@ 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)