VTK  9.1.0
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
27#ifndef vtkContext2D_h
28#define vtkContext2D_h
29
30#include "vtkDeprecation.h" // for deprecation macros
31#include "vtkObject.h"
32#include "vtkRenderingContext2DModule.h" // For export macro
33
34class vtkWindow;
35
36class vtkContext3D;
37class vtkStdString;
39class vtkTextProperty;
40
41class vtkPoints2D;
42class vtkVector2f;
43class vtkRectf;
46class vtkPen;
47class vtkBrush;
48class vtkImageData;
49class vtkPolyData;
50class vtkTransform2D;
52
53class VTKRENDERINGCONTEXT2D_EXPORT vtkContext2D : public vtkObject
54{
55public:
56 vtkTypeMacro(vtkContext2D, vtkObject);
57 void PrintSelf(ostream& os, vtkIndent indent) override;
58
62 static vtkContext2D* New();
63
70
71 vtkGetObjectMacro(Device, vtkContextDevice2D);
72
78 bool End();
79
83 bool GetBufferIdMode() const;
84
92
100
104 void DrawLine(float x1, float y1, float x2, float y2);
105
109 void DrawLine(float p[4]);
110
116
120 void DrawPoly(float* x, float* y, int n);
121
127
133 void DrawPoly(float* points, int n);
134
141 void DrawPoly(float* points, int n, unsigned char* colors, int nc_comps);
142
148
153 void DrawLines(float* points, int n);
154
158 void DrawPoint(float x, float y);
159
163 void DrawPoints(float* x, float* y, int n);
164
170
176 void DrawPoints(float* points, int n);
177
184
186
194 vtkImageData* sprite, float* points, int n, unsigned char* colors, int nc_comps);
196
202 void DrawPointSprites(vtkImageData* sprite, float* points, int n);
203
205
221 virtual void DrawMarkers(
222 int shape, bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
223 virtual void DrawMarkers(int shape, bool highlight, float* points, int n);
224 virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D* points);
225 virtual void DrawMarkers(
226 int shape, bool highlight, vtkPoints2D* points, vtkUnsignedCharArray* colors);
228
232 void DrawRect(float x, float y, float w, float h);
233
235
238 void DrawQuad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);
239 void DrawQuad(float* p);
241
243
247 void DrawQuadStrip(float* p, int n);
249
254 void DrawPolygon(float* x, float* y, int n);
255
261
267 void DrawPolygon(float* points, int n);
268
273 void DrawPolygon(float* x, float* y, int n, unsigned char* color, int nc_comps);
274
279 void DrawPolygon(vtkPoints2D* points, unsigned char* color, int nc_comps);
280
286 void DrawPolygon(float* points, int n, unsigned char* color, int nc_comps);
287
293 void DrawEllipse(float x, float y, float rx, float ry);
294
304 float x, float y, float outRadius, float inRadius, float startAngle, float stopAngle);
305
317 void DrawEllipseWedge(float x, float y, float outRx, float outRy, float inRx, float inRy,
318 float startAngle, float stopAngle);
319
325 void DrawArc(float x, float y, float r, float startAngle, float stopAngle);
326
333 void DrawEllipticArc(float x, float y, float rX, float rY, float startAngle, float stopAngle);
334
338 void DrawImage(float x, float y, vtkImageData* image);
339
344 void DrawImage(float x, float y, float scale, vtkImageData* image);
345
352
358 float x, float y, vtkPolyData* polyData, vtkUnsignedCharArray* colors, int scalarMode);
359
361
366 void DrawStringRect(vtkPoints2D* rect, const vtkStdString& string);
367 VTK_DEPRECATED_IN_9_1_0("Use void DrawStringRect(vtkPoints2D* rect, const vtkStdString& string)")
368 void DrawStringRect(vtkPoints2D* rect, const vtkUnicodeString& string);
369 void DrawStringRect(vtkPoints2D* rect, const char* string);
370 void DrawStringRect(const float rect[4], const vtkStdString& string);
372 "Use void DrawStringRect(const float rect[4], const vtkStdString& string)")
373 void DrawStringRect(const float rect[4], const vtkUnicodeString& string);
374 void DrawStringRect(const float rect[4], const char* string);
376
378
381 void DrawString(vtkPoints2D* point, const vtkStdString& string);
382 void DrawString(float x, float y, const vtkStdString& string);
383 VTK_DEPRECATED_IN_9_1_0("Use void DrawString(vtkPoints2D* point, const vtkStdString& string)")
384 void DrawString(vtkPoints2D* point, const vtkUnicodeString& string);
385 VTK_DEPRECATED_IN_9_1_0("Use void DrawString(float x, float y, const vtkStdString& string)")
386 void DrawString(float x, float y, const vtkUnicodeString& string);
387 void DrawString(vtkPoints2D* point, const char* string);
388 void DrawString(float x, float y, const char* string);
390
392
401 void ComputeStringBounds(const vtkStdString& string, vtkPoints2D* bounds);
402 void ComputeStringBounds(const vtkStdString& string, float bounds[4]);
404 "Use void ComputeStringBounds(const vtkStdString& string, vtkPoints2D* bounds)")
405 void ComputeStringBounds(const vtkUnicodeString& string, vtkPoints2D* bounds);
407 "Use void ComputeStringBounds(const vtkStdString& string, float bounds[4])")
408 void ComputeStringBounds(const vtkUnicodeString& 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
450 void DrawMathTextString(
451 vtkPoints2D* point, const vtkStdString& string, const vtkStdString& fallback);
452 void DrawMathTextString(
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
461 bool MathTextIsSupported();
462
468 void ApplyPen(vtkPen* pen);
469
475 vtkPen* GetPen();
476
482 void ApplyBrush(vtkBrush* brush);
483
488 vtkBrush* GetBrush();
489
495 void ApplyTextProp(vtkTextProperty* prop);
496
500 vtkTextProperty* GetTextProp();
501
507 void SetTransform(vtkTransform2D* transform);
508
512 vtkTransform2D* GetTransform();
513
520 void AppendTransform(vtkTransform2D* transform);
521
523
527 void PushMatrix();
528 void PopMatrix();
530
534 void ApplyId(vtkIdType id);
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
598#endif // vtkContext2D_h
2D array of ids, used for picking.
provides a brush that fills shapes drawn by vtkContext2D.
Definition: vtkBrush.h:38
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:54
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
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,...
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 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.
bool Begin(vtkContextDevice2D *device)
Begin painting on a vtkContextDevice2D, no painting can occur before this call has been made.
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 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.
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...
void DrawImage(const vtkRectf &pos, vtkImageData *image)
Draw the supplied image at the given position.
void DrawImage(float x, float y, vtkImageData *image)
Draw the supplied image at the given x, y location (bottom corner).
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...
void DrawPointSprites(vtkImageData *sprite, float *points, int n)
Draw a series of point sprites, images centred at the points supplied.
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 DrawPoly(vtkPoints2D *points)
Draw a poly line between the specified points - fastest code path due to memory layout of the coordin...
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 DrawPolygon(vtkPoints2D *points)
Draw a polygon defined by the specified points - fastest code path due to memory layout of the coordi...
void DrawLine(vtkPoints2D *points)
Draw a line between the specified points.
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...
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 DrawLines(vtkPoints2D *points)
Draw multiple lines between the specified pairs of points.
void DrawPoints(vtkPoints2D *points)
Draw a poly line between the specified points - fastest code path due to memory layout of the coordin...
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.
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...
Class for drawing 3D primitives to a graphical context.
Definition: vtkContext3D.h:41
Abstract class for drawing 2D primitives.
vtkFrustumSelector is a vtkSelector that selects elements based on whether they are inside or interse...
topologically and geometrically regular array of data
Definition: vtkImageData.h:48
a simple class to control print indentation
Definition: vtkIndent.h:34
abstract base class for most VTK objects
Definition: vtkObject.h:63
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:37
represent and manipulate 2D points
Definition: vtkPoints2D.h:34
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:86
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:36
represent text properties.
describes linear transformations via a 3x3 matrix
String class that stores Unicode text.
dynamic, self-adjusting array of unsigned char
window superclass for vtkRenderWindow
Definition: vtkWindow.h:39
@ Transform
Definition: vtkX3D.h:47
@ 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
#define VTK_DEPRECATED_IN_9_1_0(reason)
int vtkIdType
Definition: vtkType.h:332