VTK  9.3.20240328
vtkOpenGLContextDevice2D.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
3 
21 #ifndef vtkOpenGLContextDevice2D_h
22 #define vtkOpenGLContextDevice2D_h
23 
24 #include "vtkContextDevice2D.h"
25 #include "vtkRenderingContextOpenGL2Module.h" // For export macro
26 
27 #include <cstdint> // For std::uintptr_t
28 #include <list> // For std::list
29 #include <vector> // For std::vector
30 
31 VTK_ABI_NAMESPACE_BEGIN
32 class vtkMatrix4x4;
33 class vtkOpenGLExtensionManager;
34 class vtkOpenGLHelper;
36 class vtkPath;
37 class vtkRenderer;
38 class vtkShaderProgram;
39 class vtkStringToImage;
40 class vtkTransform;
42 class vtkViewport;
43 class vtkWindow;
45 
46 class VTKRENDERINGCONTEXTOPENGL2_EXPORT vtkOpenGLContextDevice2D : public vtkContextDevice2D
47 {
48 public:
50  void PrintSelf(ostream& os, vtkIndent indent) override;
51 
56 
62  void DrawPoly(float* f, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
63 
70  void DrawLines(float* f, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
71 
77  void DrawPoints(float* points, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
78  void DrawPoints(
79  vtkDataArray* positions, vtkUnsignedCharArray* colors, std::uintptr_t cacheIdentifier) override;
80 
87  void DrawPointSprites(vtkImageData* sprite, float* points, int n, unsigned char* colors = nullptr,
88  int nc_comps = 0) override;
90  std::uintptr_t cacheIdentifier) override;
91 
107  void DrawMarkers(int shape, bool highlight, float* points, int n, unsigned char* colors = nullptr,
108  int nc_comps = 0) override;
109  void DrawMarkers(int shape, bool highlight, vtkDataArray* positions, vtkUnsignedCharArray* colors,
110  std::uintptr_t cacheIdentifier) override;
111 
113 
118  vtkSetMacro(MaximumMarkerCacheSize, int);
119  vtkGetMacro(MaximumMarkerCacheSize, int);
121 
125  void DrawQuad(float* points, int n) override;
126 
130  void DrawQuadStrip(float* points, int n) override;
131 
135  void DrawPolygon(float*, int) override;
137  float* points, int numPoints, unsigned char* colors = nullptr, int nc_comps = 0) override;
138 
150  void DrawEllipseWedge(float x, float y, float outRx, float outRy, float inRx, float inRy,
151  float startAngle, float stopAngle) override;
152 
160  float x, float y, float rX, float rY, float startAngle, float stopAngle) override;
161 
165  void DrawString(float* point, const vtkStdString& string) override;
166 
175  void ComputeStringBounds(const vtkStdString& string, float bounds[4]) override;
176 
182  void ComputeJustifiedStringBounds(const char* string, float bounds[4]) override;
183 
188  void DrawMathTextString(float point[2], const vtkStdString& string) override;
189 
194  void DrawImage(float p[2], float scale, vtkImageData* image) override;
195 
201  void DrawImage(const vtkRectf& pos, vtkImageData* image) override;
202 
207  void DrawPolyData(float p[2], float scale, vtkPolyData* polyData, vtkUnsignedCharArray* colors,
208  int scalarMode) override;
209 
213  void SetColor4(unsigned char color[4]) override;
214 
218  virtual void SetColor(unsigned char color[3]);
219 
223  void SetTexture(vtkImageData* image, int properties = 0) override;
224 
228  void SetPointSize(float size) override;
229 
233  void SetLineWidth(float width) override;
234 
238  void SetLineType(int type) override;
239 
243  void MultiplyMatrix(vtkMatrix3x3* m) override;
244 
248  void SetMatrix(vtkMatrix3x3* m) override;
249 
253  void GetMatrix(vtkMatrix3x3* m) override;
254 
258  void PushMatrix() override;
259 
263  void PopMatrix() override;
264 
265  /*
266  * Supply an int array of length 4 with x1, y1, width, height specifying
267  * clipping region for the device in pixels.
268  */
269  void SetClipping(int* x) override;
270 
274  void EnableClipping(bool enable) override;
275 
279  void Begin(vtkViewport* viewport) override;
280 
284  void End() override;
285 
294 
302  void BufferIdModeEnd() override;
303 
310 
316 
320  bool HasGLSL();
321 
323 
326  vtkGetObjectMacro(RenderWindow, vtkOpenGLRenderWindow);
328 
334  virtual void ReleaseGraphicsResources(vtkWindow* window);
335 
337 
343 
344 protected:
347 
355  int GetNumberOfArcIterations(float rX, float rY, float startAngle, float stopAngle);
356 
361 
365  bool InRender;
366 
368 
371  class Private;
373 
374  class CellArrayHelper;
377 
382 
383  vtkOpenGLHelper* LinesCBO; // vertex + color
387  vtkOpenGLHelper* VCBO; // vertex + color
389  vtkOpenGLHelper* VBO; // vertex
391  vtkOpenGLHelper* VTBO; // vertex + tcoord
393  vtkOpenGLHelper* SCBO; // sprite + color
395  vtkOpenGLHelper* SBO; // sprite
397 
399  void BuildVBO(
400  vtkOpenGLHelper* cbo, float* v, int nv, unsigned char* coolors, int nc, float* tcoords);
402  std::vector<float>& tverts, unsigned char* colors = nullptr, int numComp = 0);
403  // used for stipples
404  unsigned short LinePattern;
405 
407 
412  int shape, bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
414  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 
426 
429  void DrawImageGL2PS(float p[2], vtkImageData* image);
430  void DrawImageGL2PS(float p[2], float scale, vtkImageData* image);
433 
435 
438  void DrawCircleGL2PS(float x, float y, float rX, float rY);
439  void DrawWedgeGL2PS(float x, float y, float outRx, float outRy, float inRx, float inRy);
441 
445  void AddEllipseToPath(vtkPath* path, float x, float y, float rx, float ry, bool reverse);
446 
450  void TransformPath(vtkPath* path) const;
451 
455  void TransformPoint(float& x, float& y) const;
456 
460  void TransformSize(float& dx, float& dy) const;
461 
465  void ReleaseCache(std::uintptr_t cacheIdentifier) override;
466 
467 private:
469  void operator=(const vtkOpenGLContextDevice2D&) = delete;
470 
477  vtkImageData* GetMarker(int shape, int size, bool highlight);
478 
479  class vtkMarkerCacheObject
480  {
481  public:
482  vtkTypeUInt64 Key;
483  vtkImageData* Value;
484  bool operator==(vtkTypeUInt64 key) { return this->Key == key; }
485  };
486 
487  void ComputeStringBoundsInternal(const std::string& string, float bounds[4]);
488 
489  vtkTransform* ProjectionMatrix;
490  vtkTransform* ModelMatrix;
491 
492  std::list<vtkMarkerCacheObject> MarkerCache;
493  int MaximumMarkerCacheSize;
494 
499  vtkImageData* GenerateMarker(int shape, int size, bool highlight);
500 };
501 
502 VTK_ABI_NAMESPACE_END
503 #endif // vtkOpenGLContextDevice2D_h
2D array of ids, used for picking.
Abstract class for drawing 2D primitives.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:154
topologically and geometrically regular array of data
Definition: vtkImageData.h:155
a simple class to control print indentation
Definition: vtkIndent.h:108
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:55
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:140
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.
void ReleaseCache(std::uintptr_t cacheIdentifier) override
Ask the buffer object builder to erase cache entry for given identifier.
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 DrawPointSprites(vtkImageData *sprite, vtkDataArray *positions, vtkUnsignedCharArray *colors, std::uintptr_t cacheIdentifier) override
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 DrawMarkers(int shape, bool highlight, vtkDataArray *positions, vtkUnsignedCharArray *colors, std::uintptr_t cacheIdentifier) override
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.
void DrawPoints(vtkDataArray *positions, vtkUnsignedCharArray *colors, std::uintptr_t cacheIdentifier) override
Internal buffer object builder that maintains a cache of VBO groups.
OpenGL rendering window.
concrete dataset representing a path defined by Bezier curves.
Definition: vtkPath.h:44
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:180
abstract specification for renderers
Definition: vtkRenderer.h:171
The ShaderProgram uses one or more Shader objects.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:78
base class for classes that render supplied text to an image.
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:159
dynamic, self-adjusting array of unsigned char
abstract specification for Viewports
Definition: vtkViewport.h:64
window superclass for vtkRenderWindow
Definition: vtkWindow.h:47
@ point
Definition: vtkX3D.h:236
@ key
Definition: vtkX3D.h:257
@ points
Definition: vtkX3D.h:446
@ startAngle
Definition: vtkX3D.h:486
@ scale
Definition: vtkX3D.h:229
@ type
Definition: vtkX3D.h:516
@ color
Definition: vtkX3D.h:221
@ image
Definition: vtkX3D.h:374
@ size
Definition: vtkX3D.h:253
@ string
Definition: vtkX3D.h:490
bool VTKCOMMONCORE_EXPORT operator==(const std::string &a, const vtkStringToken &b)