VTK  9.3.0
vtkContext2D.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
30#ifndef vtkContext2D_h
31#define vtkContext2D_h
32
33#include "vtkObject.h"
34#include "vtkRenderingContext2DModule.h" // For export macro
35
36#include <cstdint> // For std::uintptr_t
37
38VTK_ABI_NAMESPACE_BEGIN
39class vtkWindow;
40
41class vtkContext3D;
42class vtkStdString;
43class vtkTextProperty;
44
45class vtkPoints2D;
46class vtkDataArray;
47class vtkVector2f;
48class vtkRectf;
51class vtkPen;
52class vtkBrush;
53class vtkImageData;
54class vtkPolyData;
55class vtkTransform2D;
57
58class VTKRENDERINGCONTEXT2D_EXPORT vtkContext2D : public vtkObject
59{
60public:
61 vtkTypeMacro(vtkContext2D, vtkObject);
62 void PrintSelf(ostream& os, vtkIndent indent) override;
63
67 static vtkContext2D* New();
68
75
76 vtkGetObjectMacro(Device, vtkContextDevice2D);
77
83 bool End();
84
88 bool GetBufferIdMode() const;
89
97
105
109 void DrawLine(float x1, float y1, float x2, float y2);
110
114 void DrawLine(float p[4]);
115
120 void DrawLine(vtkPoints2D* points);
121
125 void DrawPoly(float* x, float* y, int n);
126
131 void DrawPoly(vtkPoints2D* points);
132
138 void DrawPoly(float* points, int n);
139
146 void DrawPoly(float* points, int n, unsigned char* colors, int nc_comps);
147
152 void DrawLines(vtkPoints2D* points);
153
158 void DrawLines(float* points, int n);
159
163 void DrawPoint(float x, float y);
164
168 void DrawPoints(float* x, float* y, int n);
169
174 void DrawPoints(vtkPoints2D* points);
176 vtkDataArray* positions, vtkUnsignedCharArray* colors, std::uintptr_t cacheIdentifier);
177
183 void DrawPoints(float* points, int n);
184
191
193
201 vtkImageData* sprite, float* points, int n, unsigned char* colors, int nc_comps);
203 std::uintptr_t cacheIdentifier);
205
211 void DrawPointSprites(vtkImageData* sprite, float* points, int n);
212
214
230 virtual void DrawMarkers(
231 int shape, bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
232 virtual void DrawMarkers(int shape, bool highlight, float* points, int n);
233 virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D* points);
234 virtual void DrawMarkers(
235 int shape, bool highlight, vtkPoints2D* points, vtkUnsignedCharArray* colors);
237
241 virtual void DrawMarkers(int shape, bool highlight, vtkDataArray* positions,
242 vtkUnsignedCharArray* colors, std::uintptr_t cacheIdentifier);
243
247 void DrawRect(float x, float y, float w, float h);
248
250
253 void DrawQuad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);
254 void DrawQuad(float* p);
256
258
262 void DrawQuadStrip(float* p, int n);
264
269 void DrawPolygon(float* x, float* y, int n);
270
276
282 void DrawPolygon(float* points, int n);
283
288 void DrawPolygon(float* x, float* y, int n, unsigned char* color, int nc_comps);
289
294 void DrawPolygon(vtkPoints2D* points, unsigned char* color, int nc_comps);
295
301 void DrawPolygon(float* points, int n, unsigned char* color, int nc_comps);
302
308 void DrawEllipse(float x, float y, float rx, float ry);
309
319 float x, float y, float outRadius, float inRadius, float startAngle, float stopAngle);
320
332 void DrawEllipseWedge(float x, float y, float outRx, float outRy, float inRx, float inRy,
333 float startAngle, float stopAngle);
334
340 void DrawArc(float x, float y, float r, float startAngle, float stopAngle);
341
348 void DrawEllipticArc(float x, float y, float rX, float rY, float startAngle, float stopAngle);
349
353 void DrawImage(float x, float y, vtkImageData* image);
354
359 void DrawImage(float x, float y, float scale, vtkImageData* image);
360
366 void DrawImage(const vtkRectf& pos, vtkImageData* image);
367
373 float x, float y, vtkPolyData* polyData, vtkUnsignedCharArray* colors, int scalarMode);
374
376
381 void DrawStringRect(vtkPoints2D* rect, const vtkStdString& string);
382 void DrawStringRect(vtkPoints2D* rect, const char* string);
383 void DrawStringRect(const float rect[4], const vtkStdString& string);
384 void DrawStringRect(const float rect[4], const char* string);
386
388
391 void DrawString(vtkPoints2D* point, const vtkStdString& string);
392 void DrawString(float x, float y, const vtkStdString& string);
393 void DrawString(vtkPoints2D* point, const char* string);
394 void DrawString(float x, float y, const char* string);
396
398
407 void ComputeStringBounds(const vtkStdString& string, vtkPoints2D* bounds);
408 void ComputeStringBounds(const vtkStdString& string, float bounds[4]);
409 void ComputeStringBounds(const char* string, vtkPoints2D* bounds);
410 void ComputeStringBounds(const char* string, float bounds[4]);
412
417 void ComputeJustifiedStringBounds(const char* string, float bounds[4]);
418
425 int ComputeFontSizeForBoundedString(const vtkStdString& string, float width, float height);
426
428
435 void DrawMathTextString(vtkPoints2D* point, const vtkStdString& string);
436 void DrawMathTextString(float x, float y, const vtkStdString& string);
437 void DrawMathTextString(vtkPoints2D* point, const char* string);
438 void DrawMathTextString(float x, float y, const char* string);
440
442
451 vtkPoints2D* point, const vtkStdString& string, const vtkStdString& fallback);
453 float x, float y, const vtkStdString& string, const vtkStdString& fallback);
454 void DrawMathTextString(vtkPoints2D* point, const char* string, const char* fallback);
455 void DrawMathTextString(float x, float y, const char* string, const char* fallback);
457
462
468 void ApplyPen(vtkPen* pen);
469
476
482 void ApplyBrush(vtkBrush* brush);
483
489
496
501
507 void SetTransform(vtkTransform2D* transform);
508
513
521
523
528 void PopMatrix();
530
535
541 static int FloatToInt(float x);
542
544
548 vtkGetObjectMacro(Context3D, vtkContext3D);
549 virtual void SetContext3D(vtkContext3D* context);
551
552protected:
554 ~vtkContext2D() override;
555
556 vtkContextDevice2D* Device; // The underlying device
557 vtkTransform2D* Transform; // Current transform
558
560 vtkContext3D* Context3D; // May be very temporary - get at a 3D version.
561
562private:
563 vtkContext2D(const vtkContext2D&) = delete;
564 void operator=(const vtkContext2D&) = delete;
565
572 vtkVector2f CalculateTextPosition(vtkPoints2D* rect);
573
580 vtkVector2f CalculateTextPosition(const float rect[4]);
581};
582
583inline int vtkContext2D::FloatToInt(float x)
584{
585 // Use a tolerance of 1/256 of a pixel when converting.
586 // A float has only 24 bits of precision, so we cannot
587 // make the tolerance too small. For example, a tolerance
588 // of 2^-8 means that the tolerance will be significant
589 // for float values up to 2^16 or 65536.0. But a
590 // tolerance of 2^-16 would only be significant for
591 // float values up to 2^8 or 256.0. A small tolerance
592 // disappears into insignificance when added to a large float.
593 float tol = 0.00390625; // 1.0/256.0
594 tol = (x >= 0 ? tol : -tol);
595 return static_cast<int>(x + tol);
596}
597
598VTK_ABI_NAMESPACE_END
599#endif // vtkContext2D_h
2D array of ids, used for picking.
provides a brush that fills shapes drawn by vtkContext2D.
Definition vtkBrush.h:39
Class for drawing 2D primitives to a graphical context.
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 ...
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,...
virtual void DrawMarkers(int shape, bool highlight, vtkDataArray *positions, vtkUnsignedCharArray *colors, std::uintptr_t cacheIdentifier)
Cached draw command for markers.
~vtkContext2D() override
void DrawPoints(vtkDataArray *positions, vtkUnsignedCharArray *colors, std::uintptr_t cacheIdentifier)
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...
vtkBrush * GetBrush()
Get the pen which controls the outlines of shapes as well as lines, points and related primitives.
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.
vtkPen * GetPen()
Get the pen which controls the outlines of shapes, as well as lines, points and related primitives.
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
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.
static vtkContext2D * New()
Creates a 2D Painter object.
vtkTextProperty * GetTextProp()
Get the text properties object for the vtkContext2D.
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...
vtkTransform2D * GetTransform()
Compute the current transform applied to the context.
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.
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.
void DrawPoly(vtkPoints2D *points)
Draw a poly line between the specified points - fastest code path due to memory layout of the coordin...
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
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
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
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 DrawPointSprites(vtkImageData *sprite, vtkDataArray *positions, vtkUnsignedCharArray *colors, std::uintptr_t cacheIdentifier)
Draw a series of point sprites, images centred at the points supplied.
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.
Abstract class for drawing 2D primitives.
abstract superclass for arrays of numeric data
topologically and geometrically regular array of data
a simple class to control print indentation
Definition vtkIndent.h:38
abstract base class for most VTK objects
Definition vtkObject.h:58
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition vtkPen.h:38
represent and manipulate 2D points
Definition vtkPoints2D.h:26
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition vtkPolyData.h:89
Computes the portion of a dataset which is inside a selection.
Wrapper around std::string to keep symbols short.
represent text properties.
describes linear transformations via a 3x3 matrix
dynamic, self-adjusting array of unsigned char
window superclass for vtkRenderWindow
Definition vtkWindow.h:34
int vtkIdType
Definition vtkType.h:315