VTK
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
33#ifndef vtkContext2D_h
34#define vtkContext2D_h
35
36#include "vtkRenderingContext2DModule.h" // For export macro
37#include "vtkObject.h"
38
39class vtkWindow;
40
41class vtkContext3D;
42class vtkStdString;
44class vtkTextProperty;
45
46class vtkPoints2D;
47class vtkVector2f;
48class vtkRectf;
51class vtkPen;
52class vtkBrush;
53class vtkImageData;
54class vtkTransform2D;
56
57class VTKRENDERINGCONTEXT2D_EXPORT vtkContext2D : public vtkObject
58{
59public:
60 vtkTypeMacro(vtkContext2D, vtkObject);
61 virtual void PrintSelf(ostream &os, vtkIndent indent);
62
66 static vtkContext2D *New();
67
74
75 vtkGetObjectMacro(Device, vtkContextDevice2D);
76
82 bool End();
83
87 bool GetBufferIdMode() const;
88
96
104
108 void DrawLine(float x1, float y1, float x2, float y2);
109
113 void DrawLine(float p[4]);
114
120
124 void DrawPoly(float *x, float *y, int n);
125
131
137 void DrawPoly(float *points, int n);
138
145 void DrawPoly(float *points, int n,
146 unsigned char *colors, int nc_comps);
147
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
175
181 void DrawPoints(float *points, int n);
182
189
191
198 vtkUnsignedCharArray *colors);
199 void DrawPointSprites(vtkImageData *sprite, float *points, int n,
200 unsigned char *colors, int nc_comps);
202
208 void DrawPointSprites(vtkImageData *sprite, float *points, int n);
209
211
223 virtual void DrawMarkers(int shape, bool highlight, float *points, int n,
224 unsigned char *colors, int nc_comps);
225 virtual void DrawMarkers(int shape, bool highlight, float *points, int n);
226 virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D *points);
227 virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D *points,
228 vtkUnsignedCharArray *colors);
230
234 void DrawRect(float x, float y, float w, float h);
235
237
240 void DrawQuad(float x1, float y1, float x2, float y2,
241 float x3, float y3, float x4, float y4);
242 void DrawQuad(float *p);
244
246
250 void DrawQuadStrip(float *p, int n);
252
257 void DrawPolygon(float *x, float *y, int n);
258
264
270 void DrawPolygon(float *points, int n);
271
277 void DrawEllipse(float x, float y, float rx, float ry);
278
287 void DrawWedge(float x, float y, float outRadius,
288 float inRadius,float startAngle,
289 float stopAngle);
290
302 void DrawEllipseWedge(float x, float y, float outRx, float outRy,
303 float inRx, float inRy, float startAngle,
304 float stopAngle);
305
306
312 void DrawArc(float x, float y, float r, float startAngle,
313 float stopAngle);
314
321 void DrawEllipticArc(float x, float y, float rX, float rY, float startAngle,
322 float stopAngle);
323
324
328 void DrawImage(float x, float y, vtkImageData *image);
329
334 void DrawImage(float x, float y, float scale, vtkImageData *image);
335
342
344
349 void DrawStringRect(vtkPoints2D *rect, const vtkStdString &string);
350 void DrawStringRect(vtkPoints2D *rect, const vtkUnicodeString &string);
351 void DrawStringRect(vtkPoints2D *rect, const char* string);
353
355
359 void DrawString(float x, float y, const vtkStdString &string);
361 void DrawString(float x, float y, const vtkUnicodeString &string);
362 void DrawString(vtkPoints2D *point, const char* string);
363 void DrawString(float x, float y, const char* string);
365
367
376 void ComputeStringBounds(const vtkStdString &string, vtkPoints2D *bounds);
377 void ComputeStringBounds(const vtkStdString &string, float bounds[4]);
379 void ComputeStringBounds(const vtkUnicodeString &string, float bounds[4]);
380 void ComputeStringBounds(const char* string, vtkPoints2D *bounds);
381 void ComputeStringBounds(const char* string, float bounds[4]);
383
389 void ComputeJustifiedStringBounds(const char* string, float bounds[4]);
390
397 int ComputeFontSizeForBoundedString(const vtkStdString &string, float width,
398 float height);
399
401
409 void DrawMathTextString(float x, float y, const vtkStdString &string);
410 void DrawMathTextString(vtkPoints2D *point, const char *string);
411 void DrawMathTextString(float x, float y, const char *string);
413
415
424 const vtkStdString &fallback);
425 void DrawMathTextString(float x, float y, const vtkStdString &string,
426 const vtkStdString &fallback);
427 void DrawMathTextString(vtkPoints2D *point, const char *string,
428 const char *fallback);
429 void DrawMathTextString(float x, float y, const char *string,
430 const char *fallback);
432
433
438
444 void ApplyPen(vtkPen *pen);
445
452
458 void ApplyBrush(vtkBrush *brush);
459
465
472
477
483 void SetTransform(vtkTransform2D *transform);
484
489
497
499
504 void PopMatrix();
506
511
517 static int FloatToInt(float x);
518
520
524 vtkGetObjectMacro(Context3D, vtkContext3D)
525 virtual void SetContext3D(vtkContext3D *context);
527
528protected:
531
532 vtkContextDevice2D *Device; // The underlying device
533 vtkTransform2D *Transform; // Current transform
534
536 vtkContext3D *Context3D; // May be very temporary - get at a 3D version.
537
538private:
539 vtkContext2D(const vtkContext2D &) VTK_DELETE_FUNCTION;
540 void operator=(const vtkContext2D &) VTK_DELETE_FUNCTION;
541
548 vtkVector2f CalculateTextPosition(vtkPoints2D* rect);
549
556 vtkVector2f CalculateTextPosition(float rect[4]);
557
558};
559
560inline int vtkContext2D::FloatToInt(float x)
561{
562 // Use a tolerance of 1/256 of a pixel when converting.
563 // A float has only 24 bits of precision, so we cannot
564 // make the tolerance too small. For example, a tolerance
565 // of 2^-8 means that the tolerance will be significant
566 // for float values up to 2^16 or 65536.0. But a
567 // tolerance of 2^-16 would only be significant for
568 // float values up to 2^8 or 256.0. A small tolerance
569 // disappears into insignificance when added to a large float.
570 float tol = 0.00390625; // 1.0/256.0
571 tol = (x >= 0 ? tol : -tol);
572 return static_cast<int>(x + tol);
573}
574
575#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:58
void DrawStringRect(vtkPoints2D *rect, const vtkUnicodeString &string)
void DrawString(float x, float y, const vtkStdString &string)
void ComputeStringBounds(const vtkUnicodeString &string, float bounds[4])
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 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)
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)
void DrawMathTextString(float x, float y, const vtkStdString &string)
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 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.
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])
void DrawQuad(float *p)
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 DrawString(vtkPoints2D *point, const vtkUnicodeString &string)
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 DrawImage(const vtkRectf &pos, vtkImageData *image)
Draw the supplied image at the given position.
void DrawMathTextString(vtkPoints2D *point, const char *string)
void DrawImage(float x, float y, vtkImageData *image)
Draw the supplied image at the given x, y location (bottom corner).
void ComputeStringBounds(const vtkUnicodeString &string, vtkPoints2D *bounds)
void DrawMathTextString(float x, float y, const char *string)
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...
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])
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)
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.
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)
virtual void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
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)
virtual void DrawMarkers(int shape, bool highlight, float *points, int n)
void DrawLine(float p[4])
Draw a line between the specified points.
void DrawMathTextString(float x, float y, const char *string, const char *fallback)
void ComputeJustifiedStringBounds(const char *string, float bounds[4])
Compute the bounds of the supplied string while taking into account the justification of the currentl...
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 DrawString(float x, float y, const vtkUnicodeString &string)
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)
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)
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 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)
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)
void DrawLine(float x1, float y1, float x2, float y2)
Draw a line between the specified points.
void DrawString(vtkPoints2D *point, const char *string)
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 PopMatrix()
Class for drawing 3D primitives to a graphical context.
Definition: vtkContext3D.h:41
Abstract class for drawing 2D primitives.
topologically and geometrically regular array of data
Definition: vtkImageData.h:46
a simple class to control print indentation
Definition: vtkIndent.h:40
abstract base class for most VTK objects
Definition: vtkObject.h:60
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:40
represent and manipulate 2D points
Definition: vtkPoints2D.h:37
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:49
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:35
Transform
Definition: ADIOSDefs.h:40
@ point
Definition: vtkX3D.h:236
@ points
Definition: vtkX3D.h:446
@ startAngle
Definition: vtkX3D.h:486
@ scale
Definition: vtkX3D.h:229
@ height
Definition: vtkX3D.h:254
@ image
Definition: vtkX3D.h:374
int vtkIdType
Definition: vtkType.h:287