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 
63  static vtkOpenGLContextDevice2D* New();
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;
138  void DrawColoredPolygon(
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 
161  void DrawEllipticArc(
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 
295  void BufferIdModeBegin(vtkAbstractContextBufferId* bufferId) override;
296 
304  void BufferIdModeEnd() override;
305 
311  bool SetStringRendererToFreeType();
312 
317  bool SetStringRendererToQt();
318 
322  bool HasGLSL();
323 
325 
328  vtkGetObjectMacro(RenderWindow, vtkOpenGLRenderWindow);
330 
336  virtual void ReleaseGraphicsResources(vtkWindow* window);
337 
339 
342  vtkMatrix4x4* GetProjectionMatrix();
343  vtkMatrix4x4* GetModelMatrix();
345 
346 protected:
348  ~vtkOpenGLContextDevice2D() override;
349 
357  int GetNumberOfArcIterations(float rX, float rY, float startAngle, float stopAngle);
358 
363 
367  bool InRender;
368 
370 
373  class Private;
374  Private* Storage;
375 
379 
384 
385  vtkOpenGLHelper* LinesCBO; // vertex + color
386  void ReadyLinesCBOProgram();
388  void ReadyLinesBOProgram();
389  vtkOpenGLHelper* VCBO; // vertex + color
390  void ReadyVCBOProgram();
391  vtkOpenGLHelper* VBO; // vertex
392  void ReadyVBOProgram();
393  vtkOpenGLHelper* VTBO; // vertex + tcoord
394  void ReadyVTBOProgram();
395  vtkOpenGLHelper* SCBO; // sprite + color
396  void ReadySCBOProgram();
397  vtkOpenGLHelper* SBO; // sprite
398  void ReadySBOProgram();
399 
400  void SetMatrices(vtkShaderProgram* prog);
401  void BuildVBO(
402  vtkOpenGLHelper* cbo, float* v, int nv, unsigned char* coolors, int nc, float* tcoords);
403  void CoreDrawTriangles(
404  std::vector<float>& tverts, unsigned char* colors = nullptr, int numComp = 0);
405  // used for stipples
406  unsigned short LinePattern;
407 
409 
413  void DrawMarkersGL2PS(
414  int shape, bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
415  void DrawCrossMarkersGL2PS(
416  bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
417  void DrawPlusMarkersGL2PS(
418  bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
419  void DrawSquareMarkersGL2PS(
420  bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
421  void DrawCircleMarkersGL2PS(
422  bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
423  void DrawDiamondMarkersGL2PS(
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);
433  void DrawImageGL2PS(const vtkRectf& rect, 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
OpenGL rendering window.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:38
virtual void SetMatrix(vtkMatrix3x3 *m)=0
Set the model view matrix for the display.
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:41
virtual void DrawPointSprites(vtkImageData *sprite, float *points, int n, unsigned char *colors=nullptr, int nc_comps=0)=0
Draw a series of point sprites, images centred at the points supplied.
virtual void SetClipping(int *x)=0
Supply an int array of length 4 with x1, y1, width, height specifying clipping region for the device ...
virtual void BufferIdModeEnd()
Finalize BufferId creation Mode.
virtual void ComputeJustifiedStringBounds(const char *string, float bounds[4])=0
Compute the bounds of the supplied string while taking into account the justification of the currentl...
virtual void DrawPoly(float *points, int n, unsigned char *colors=nullptr, int nc_comps=0)=0
Draw a poly line using the points - fastest code path due to memory layout of the coordinates...
concrete dataset representing a path defined by Bezier curves.
Definition: vtkPath.h:35
abstract specification for Viewports
Definition: vtkViewport.h:55
virtual void DrawPolygon(float *p, int n)
Draw a polygon using the specified number of points.
Class for drawing 2D primitives using OpenGL 1.1+.
virtual void BufferIdModeBegin(vtkAbstractContextBufferId *bufferId)
Start BufferId creation Mode.
abstract specification for renderers
Definition: vtkRenderer.h:72
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:90
virtual void DrawPolyData(float p[2], float scale, vtkPolyData *polyData, vtkUnsignedCharArray *colors, int scalarMode)
Draw the supplied PolyData at the given x, y (p[0], p[1]) (bottom corner), scaled by scale (1...
virtual void Begin(vtkViewport *)
Begin drawing, pass in the viewport to set up the view.
base class for classes that render supplied text to an image.
virtual void SetColor4(unsigned char color[4])=0
Set the color for the device using unsigned char of length 4, RGBA.
bool InRender
Is the device currently rendering? Prevent multiple End() calls.
window superclass for vtkRenderWindow
Definition: vtkWindow.h:38
virtual void EnableClipping(bool enable)=0
Enable or disable the clipping of the scene.
virtual void SetLineWidth(float width)=0
Set the line width.
virtual void DrawPoints(float *points, int n, unsigned char *colors=nullptr, int nc_comps=0)=0
Draw a series of points - fastest code path due to memory layout of the coordinates.
bool VTKCOMMONDATAMODEL_EXPORT operator==(vtkEdgeBase e1, vtkEdgeBase e2)
vtkOpenGLRenderWindow * RenderWindow
The OpenGL render window being used by the device.
a simple class to control print indentation
Definition: vtkIndent.h:39
virtual void DrawMarkers(int shape, bool highlight, float *points, int n, unsigned char *colors=nullptr, int nc_comps=0)
Draw a series of markers centered at the points supplied.
topologically and geometrically regular array of data
Definition: vtkImageData.h:53
virtual void DrawQuadStrip(float *, int)
Draw a quad using the specified number of points.
Abstract class for drawing 2D primitives.
virtual void PopMatrix()=0
Pop the current matrix off of the stack.
virtual void DrawLines(float *f, int n, unsigned char *colors=nullptr, int nc_comps=0)=0
Draw lines using the points - memory layout is as follows: l1p1,l1p2,l2p1,l2p2... ...
virtual void SetTexture(vtkImageData *image, int properties)=0
Set the texture for the device, it is used to fill the polygons.
virtual void DrawMathTextString(float *point, const vtkStdString &string)=0
Draw text using MathText markup for mathematical equations.
virtual void SetPointSize(float size)=0
Set the point size for glyphs/sprites.
dynamic, self-adjusting array of unsigned char
virtual void DrawQuad(float *, int)
Draw a quad using the specified number of points.
2D array of ids, used for picking.
virtual void DrawEllipticArc(float x, float y, float rX, float rY, float startAngle, float stopAngle)=0
Draw an elliptic arc with center at x,y with radii rX and rY between angles startAngle and stopAngle ...
virtual void MultiplyMatrix(vtkMatrix3x3 *m)=0
Multiply the current model view matrix by the supplied one.
virtual void DrawString(float *point, const vtkStdString &string)=0
Draw some text to the screen.
virtual void End()
End drawing, clean up the view.
virtual void DrawEllipseWedge(float x, float y, float outRx, float outRy, float inRx, float inRy, float startAngle, float stopAngle)=0
Draw an elliptic wedge with center at x, y, outer radii outRx, outRy, inner radii inRx...
virtual void DrawColoredPolygon(float *points, int numPoints, unsigned char *colors=nullptr, int nc_comps=0)
Draw a polygon using the specified number of points.
vtkRenderer * Renderer
We need to store a pointer to the renderer for the text rendering.
virtual void GetMatrix(vtkMatrix3x3 *m)=0
Set the model view matrix for the display.
virtual void ComputeStringBounds(const vtkStdString &string, float bounds[4])=0
Compute the bounds of the supplied string.
virtual void PushMatrix()=0
Push the current matrix onto the stack.
virtual void DrawImage(float p[2], float scale, vtkImageData *image)=0
Draw the supplied image at the given x, y (p[0], p[1]) (bottom corner), scaled by scale (1...
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:36
virtual void SetLineType(int type)=0
Set the line type type (using anonymous enum in vtkPen).
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
The ShaderProgram uses one or more Shader objects.