VTK  9.2.5
vtkContext2D.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkContext2D.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 vtkContext2D_h
53 #define vtkContext2D_h
54 
55 #include "vtkObject.h"
56 #include "vtkRenderingContext2DModule.h" // For export macro
57 
58 class vtkWindow;
59 
60 class vtkContext3D;
61 class vtkStdString;
62 class vtkTextProperty;
63 
64 class vtkPoints2D;
65 class vtkVector2f;
66 class vtkRectf;
68 class vtkContextDevice2D;
69 class vtkPen;
70 class vtkBrush;
71 class vtkImageData;
72 class vtkPolyData;
73 class vtkTransform2D;
75 
76 class VTKRENDERINGCONTEXT2D_EXPORT vtkContext2D : public vtkObject
77 {
78 public:
79  vtkTypeMacro(vtkContext2D, vtkObject);
80  void PrintSelf(ostream& os, vtkIndent indent) override;
81 
85  static vtkContext2D* New();
86 
92  bool Begin(vtkContextDevice2D* device);
93 
94  vtkGetObjectMacro(Device, vtkContextDevice2D);
95 
101  bool End();
102 
106  bool GetBufferIdMode() const;
107 
115 
123 
127  void DrawLine(float x1, float y1, float x2, float y2);
128 
132  void DrawLine(float p[4]);
133 
139 
143  void DrawPoly(float* x, float* y, int n);
144 
150 
156  void DrawPoly(float* points, int n);
157 
164  void DrawPoly(float* points, int n, unsigned char* colors, int nc_comps);
165 
171 
176  void DrawLines(float* points, int n);
177 
181  void DrawPoint(float x, float y);
182 
186  void DrawPoints(float* x, float* y, int n);
187 
193 
199  void DrawPoints(float* points, int n);
200 
207 
209 
217  vtkImageData* sprite, float* points, int n, unsigned char* colors, int nc_comps);
219 
225  void DrawPointSprites(vtkImageData* sprite, float* points, int n);
226 
228 
244  virtual void DrawMarkers(
245  int shape, bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
246  virtual void DrawMarkers(int shape, bool highlight, float* points, int n);
247  virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D* points);
248  virtual void DrawMarkers(
249  int shape, bool highlight, vtkPoints2D* points, vtkUnsignedCharArray* colors);
251 
255  void DrawRect(float x, float y, float w, float h);
256 
258 
261  void DrawQuad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);
262  void DrawQuad(float* p);
264 
266 
270  void DrawQuadStrip(float* p, int n);
272 
277  void DrawPolygon(float* x, float* y, int n);
278 
284 
290  void DrawPolygon(float* points, int n);
291 
296  void DrawPolygon(float* x, float* y, int n, unsigned char* color, int nc_comps);
297 
302  void DrawPolygon(vtkPoints2D* points, unsigned char* color, int nc_comps);
303 
309  void DrawPolygon(float* points, int n, unsigned char* color, int nc_comps);
310 
316  void DrawEllipse(float x, float y, float rx, float ry);
317 
326  void DrawWedge(
327  float x, float y, float outRadius, float inRadius, float startAngle, float stopAngle);
328 
340  void DrawEllipseWedge(float x, float y, float outRx, float outRy, float inRx, float inRy,
341  float startAngle, float stopAngle);
342 
348  void DrawArc(float x, float y, float r, float startAngle, float stopAngle);
349 
356  void DrawEllipticArc(float x, float y, float rX, float rY, float startAngle, float stopAngle);
357 
361  void DrawImage(float x, float y, vtkImageData* image);
362 
367  void DrawImage(float x, float y, float scale, vtkImageData* image);
368 
374  void DrawImage(const vtkRectf& pos, vtkImageData* image);
375 
381  float x, float y, vtkPolyData* polyData, vtkUnsignedCharArray* colors, int scalarMode);
382 
384 
389  void DrawStringRect(vtkPoints2D* rect, const vtkStdString& string);
390  void DrawStringRect(vtkPoints2D* rect, const char* string);
391  void DrawStringRect(const float rect[4], const vtkStdString& string);
392  void DrawStringRect(const float rect[4], const char* string);
394 
396 
399  void DrawString(vtkPoints2D* point, const vtkStdString& string);
400  void DrawString(float x, float y, const vtkStdString& string);
401  void DrawString(vtkPoints2D* point, const char* string);
402  void DrawString(float x, float y, const char* string);
404 
406 
415  void ComputeStringBounds(const vtkStdString& string, vtkPoints2D* bounds);
416  void ComputeStringBounds(const vtkStdString& string, float bounds[4]);
417  void ComputeStringBounds(const char* string, vtkPoints2D* bounds);
418  void ComputeStringBounds(const char* string, float bounds[4]);
420 
425  void ComputeJustifiedStringBounds(const char* string, float bounds[4]);
426 
433  int ComputeFontSizeForBoundedString(const vtkStdString& string, float width, float height);
434 
436 
444  void DrawMathTextString(float x, float y, const vtkStdString& string);
445  void DrawMathTextString(vtkPoints2D* point, const char* string);
446  void DrawMathTextString(float x, float y, const char* string);
448 
450 
459  vtkPoints2D* point, const vtkStdString& string, const vtkStdString& fallback);
461  float x, float y, const vtkStdString& string, const vtkStdString& fallback);
462  void DrawMathTextString(vtkPoints2D* point, const char* string, const char* fallback);
463  void DrawMathTextString(float x, float y, const char* string, const char* fallback);
465 
470 
476  void ApplyPen(vtkPen* pen);
477 
484 
490  void ApplyBrush(vtkBrush* brush);
491 
497 
504 
509 
515  void SetTransform(vtkTransform2D* transform);
516 
521 
528  void AppendTransform(vtkTransform2D* transform);
529 
531 
535  void PushMatrix();
536  void PopMatrix();
538 
542  void ApplyId(vtkIdType id);
543 
549  static int FloatToInt(float x);
550 
552 
556  vtkGetObjectMacro(Context3D, vtkContext3D);
557  virtual void SetContext3D(vtkContext3D* context);
559 
560 protected:
562  ~vtkContext2D() override;
563 
564  vtkContextDevice2D* Device; // The underlying device
565  vtkTransform2D* Transform; // Current transform
566 
568  vtkContext3D* Context3D; // May be very temporary - get at a 3D version.
569 
570 private:
571  vtkContext2D(const vtkContext2D&) = delete;
572  void operator=(const vtkContext2D&) = delete;
573 
580  vtkVector2f CalculateTextPosition(vtkPoints2D* rect);
581 
588  vtkVector2f CalculateTextPosition(const float rect[4]);
589 };
590 
591 inline int vtkContext2D::FloatToInt(float x)
592 {
593  // Use a tolerance of 1/256 of a pixel when converting.
594  // A float has only 24 bits of precision, so we cannot
595  // make the tolerance too small. For example, a tolerance
596  // of 2^-8 means that the tolerance will be significant
597  // for float values up to 2^16 or 65536.0. But a
598  // tolerance of 2^-16 would only be significant for
599  // float values up to 2^8 or 256.0. A small tolerance
600  // disappears into insignificance when added to a large float.
601  float tol = 0.00390625; // 1.0/256.0
602  tol = (x >= 0 ? tol : -tol);
603  return static_cast<int>(x + tol);
604 }
605 
606 #endif // vtkContext2D_h
2D array of ids, used for picking.
provides a brush that fills shapes drawn by vtkContext2D.
Definition: vtkBrush.h:100
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:77
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void DrawString(float x, float y, const vtkStdString &string)
Draw some text to the screen.
static int FloatToInt(float x)
Float to int conversion, performs truncation but with a rounding tolerance for float values that are ...
Definition: vtkContext2D.h:591
void DrawEllipseWedge(float x, float y, float outRx, float outRy, float inRx, float inRy, float startAngle, float stopAngle)
Draw an elliptic wedge with center at x, y, outer radii outRx, outRy, inner radii inRx,...
~vtkContext2D() override
void SetTransform(vtkTransform2D *transform)
Set the transform for the context, the underlying device will use the matrix of the transform.
void DrawString(float x, float y, const char *string)
Draw some text to the screen.
void DrawMathTextString(vtkPoints2D *point, const vtkStdString &string)
Draw a MathText formatted equation to the screen.
void DrawArc(float x, float y, float r, float startAngle, float stopAngle)
Draw a circular arc with center at x,y with radius r between angles startAngle and stopAngle (express...
void DrawPoly(float *x, float *y, int n)
Draw a poly line between the specified points.
void DrawStringRect(vtkPoints2D *rect, const vtkStdString &string)
Draw some text to the screen in a bounding rectangle with the alignment of the text properties respec...
void DrawPoints(float *points, int n)
Draw a poly line between the specified points, where the float array is of size 2*n and the points ar...
void DrawQuadStrip(vtkPoints2D *points)
Draw a strip of quads.
void ComputeStringBounds(const char *string, vtkPoints2D *bounds)
Compute the bounds of the supplied string.
void DrawMathTextString(float x, float y, const vtkStdString &string)
Draw a MathText formatted equation to the screen.
void DrawPointSprites(vtkImageData *sprite, vtkPoints2D *points)
Draw a series of point sprites, images centred at the points supplied.
void DrawPoint(float x, float y)
Draw a point at the supplied x and y coordinate.
void DrawPolygon(float *x, float *y, int n, unsigned char *color, int nc_comps)
Draw a polygon specified specified by the points using the x and y arrays supplied.
void DrawWedge(float x, float y, float outRadius, float inRadius, float startAngle, float stopAngle)
Draw a circular wedge with center at x, y, outer radius outRadius, inner radius inRadius between angl...
void DrawPointSprites(vtkImageData *sprite, vtkPoints2D *points, vtkUnsignedCharArray *colors)
Draw a series of point sprites, images centred at the points supplied.
bool GetBufferIdMode() const
Tell if the context is in BufferId creation mode.
vtkTransform2D * Transform
Definition: vtkContext2D.h:565
void ApplyPen(vtkPen *pen)
Apply the supplied pen which controls the outlines of shapes, as well as lines, points and related pr...
void AppendTransform(vtkTransform2D *transform)
Append the transform for the context, the underlying device will use the matrix of the transform.
void ApplyId(vtkIdType id)
Apply id as a color.
void PushMatrix()
Push/pop the transformation matrix for the painter (sets the underlying matrix for the device when av...
bool Begin(vtkContextDevice2D *device)
Begin painting on a vtkContextDevice2D, no painting can occur before this call has been made.
void DrawString(vtkPoints2D *point, const vtkStdString &string)
Draw some text to the screen.
void DrawEllipticArc(float x, float y, float rX, float rY, float startAngle, float stopAngle)
Draw an elliptic arc with center at x,y with radii rX and rY between angles startAngle and stopAngle ...
void ComputeStringBounds(const char *string, float bounds[4])
Compute the bounds of the supplied string.
void DrawQuad(float *p)
Draw a quadrilateral at the specified points (4 points, 8 floats in x, y).
void DrawRect(float x, float y, float w, float h)
Draw a rectangle with origin at x, y and width w, height h.
void DrawPoly(float *points, int n, unsigned char *colors, int nc_comps)
Draw a poly line between the specified points, where the float array is of size 2*n and the points ar...
bool End()
Ends painting on the device, you would not usually need to call this as it should be called by the de...
vtkPen * GetPen()
Get the pen which controls the outlines of shapes, as well as lines, points and related primitives.
void DrawStringRect(const float rect[4], const vtkStdString &string)
Draw some text to the screen in a bounding rectangle with the alignment of the text properties respec...
void DrawImage(const vtkRectf &pos, vtkImageData *image)
Draw the supplied image at the given position.
void DrawMathTextString(vtkPoints2D *point, const char *string)
Draw a MathText formatted equation to the screen.
void DrawImage(float x, float y, vtkImageData *image)
Draw the supplied image at the given x, y location (bottom corner).
void DrawMathTextString(float x, float y, const char *string)
Draw a MathText formatted equation to the screen.
void DrawPolygon(float *points, int n)
Draw a polygon defined by the specified points, where the float array is of size 2*n and the points a...
void DrawPolygon(float *points, int n, unsigned char *color, int nc_comps)
Draw a polygon defined by the specified points, where the float array is of size 2*n and the points a...
int ComputeFontSizeForBoundedString(const vtkStdString &string, float width, float height)
Calculate the largest possible font size where the supplied string will fit within the specified boun...
void DrawPointSprites(vtkImageData *sprite, float *points, int n)
Draw a series of point sprites, images centred at the points supplied.
vtkTransform2D * GetTransform()
Compute the current transform applied to the context.
void ComputeStringBounds(const vtkStdString &string, float bounds[4])
Compute the bounds of the supplied string.
void DrawPoints(float *x, float *y, int n)
Draw the specified number of points using the x and y arrays supplied.
virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D *points)
Draw a series of markers centered at the points supplied.
void DrawPolygon(float *x, float *y, int n)
Draw a polygon specified specified by the points using the x and y arrays supplied.
void BufferIdModeBegin(vtkAbstractContextBufferId *bufferId)
Start BufferId creation Mode.
void DrawStringRect(const float rect[4], const char *string)
Draw some text to the screen in a bounding rectangle with the alignment of the text properties respec...
bool MathTextIsSupported()
Return true if MathText rendering available on the current device.
static vtkContext2D * New()
Creates a 2D Painter object.
void DrawPoly(vtkPoints2D *points)
Draw a poly line between the specified points - fastest code path due to memory layout of the coordin...
vtkBrush * GetBrush()
Get the pen which controls the outlines of shapes as well as lines, points and related primitives.
vtkTextProperty * GetTextProp()
Get the text properties object for the vtkContext2D.
void DrawMathTextString(vtkPoints2D *point, const char *string, const char *fallback)
Draw a MathText formatted equation to the screen.
void ApplyTextProp(vtkTextProperty *prop)
Apply the supplied text property which controls how text is rendered.
void DrawPointSprites(vtkImageData *sprite, float *points, int n, unsigned char *colors, int nc_comps)
Draw a series of point sprites, images centred at the points supplied.
virtual void DrawMarkers(int shape, bool highlight, float *points, int n)
Draw a series of markers centered at the points supplied.
void DrawLine(float p[4])
Draw a line between the specified points.
void DrawMathTextString(float x, float y, const char *string, const char *fallback)
Draw a MathText formatted equation to the screen.
void ComputeJustifiedStringBounds(const char *string, float bounds[4])
Compute the bounds of the supplied string while taking into account the justification and rotation of...
void DrawPolygon(vtkPoints2D *points)
Draw a polygon defined by the specified points - fastest code path due to memory layout of the coordi...
vtkAbstractContextBufferId * BufferId
Definition: vtkContext2D.h:567
void DrawLine(vtkPoints2D *points)
Draw a line between the specified points.
virtual void SetContext3D(vtkContext3D *context)
Get the vtkContext3D device, in order to do some 3D rendering.
void ApplyBrush(vtkBrush *brush)
Apply the supplied brush which controls the outlines of shapes, as well as lines, points and related ...
void DrawStringRect(vtkPoints2D *rect, const char *string)
Draw some text to the screen in a bounding rectangle with the alignment of the text properties respec...
void ComputeStringBounds(const vtkStdString &string, vtkPoints2D *bounds)
Compute the bounds of the supplied string.
void DrawImage(float x, float y, float scale, vtkImageData *image)
Draw the supplied image at the given x, y location (bottom corner).
void BufferIdModeEnd()
Finalize BufferId creation Mode.
void DrawQuad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
Draw a quadrilateral at the specified points (4 points, 8 floats in x, y).
void DrawQuadStrip(float *p, int n)
Draw a strip of quads.
void DrawPoly(float *points, int n)
Draw a poly line between the specified points, where the float array is of size 2*n and the points ar...
vtkContextDevice2D * Device
Definition: vtkContext2D.h:564
void DrawEllipse(float x, float y, float rx, float ry)
Draw an ellipse with center at x, y and radii rx, ry.
void DrawLines(float *points, int n)
Draw multiple lines between the specified pairs of points.
void DrawMathTextString(vtkPoints2D *point, const vtkStdString &string, const vtkStdString &fallback)
Draw a MathText formatted equation to the screen.
void DrawLines(vtkPoints2D *points)
Draw multiple lines between the specified pairs of points.
void DrawMathTextString(float x, float y, const vtkStdString &string, const vtkStdString &fallback)
Draw a MathText formatted equation to the screen.
void DrawPoints(vtkPoints2D *points)
Draw a poly line between the specified points - fastest code path due to memory layout of the coordin...
vtkContext3D * Context3D
Definition: vtkContext2D.h:568
virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D *points, vtkUnsignedCharArray *colors)
Draw a series of markers centered at the points supplied.
void DrawPolyData(float x, float y, vtkPolyData *polyData, vtkUnsignedCharArray *colors, int scalarMode)
Draw the supplied polyData at the given x, y position (bottom corner).
void DrawLine(float x1, float y1, float x2, float y2)
Draw a line between the specified points.
void DrawString(vtkPoints2D *point, const char *string)
Draw some text to the screen.
virtual void DrawMarkers(int shape, bool highlight, float *points, int n, unsigned char *colors, int nc_comps)
Draw a series of markers centered at the points supplied.
void DrawPolygon(vtkPoints2D *points, unsigned char *color, int nc_comps)
Draw a polygon defined by the specified points - fastest code path due to memory layout of the coordi...
void PopMatrix()
Push/pop the transformation matrix for the painter (sets the underlying matrix for the device when av...
Class for drawing 3D primitives to a graphical context.
Definition: vtkContext3D.h:60
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
abstract base class for most VTK objects
Definition: vtkObject.h:82
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:139
represent and manipulate 2D points
Definition: vtkPoints2D.h:37
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:200
Computes the portion of a dataset which is inside a selection.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:108
represent text properties.
describes linear transformations via a 3x3 matrix
dynamic, self-adjusting array of unsigned char
window superclass for vtkRenderWindow
Definition: vtkWindow.h:39
@ point
Definition: vtkX3D.h:242
@ points
Definition: vtkX3D.h:452
@ startAngle
Definition: vtkX3D.h:492
@ scale
Definition: vtkX3D.h:235
@ color
Definition: vtkX3D.h:227
@ height
Definition: vtkX3D.h:260
@ image
Definition: vtkX3D.h:380
int vtkIdType
Definition: vtkType.h:332