VTK  9.0.1
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 "vtkObject.h"
31 #include "vtkRenderingContext2DModule.h" // For export macro
32 
33 class vtkWindow;
34 
35 class vtkContext3D;
36 class vtkStdString;
37 class vtkUnicodeString;
38 class vtkTextProperty;
39 
40 class vtkPoints2D;
41 class vtkVector2f;
42 class vtkRectf;
44 class vtkContextDevice2D;
45 class vtkPen;
46 class vtkBrush;
47 class vtkImageData;
48 class vtkPolyData;
49 class vtkTransform2D;
51 
52 class VTKRENDERINGCONTEXT2D_EXPORT vtkContext2D : public vtkObject
53 {
54 public:
55  vtkTypeMacro(vtkContext2D, vtkObject);
56  void PrintSelf(ostream& os, vtkIndent indent) override;
57 
61  static vtkContext2D* New();
62 
68  bool Begin(vtkContextDevice2D* device);
69 
70  vtkGetObjectMacro(Device, vtkContextDevice2D);
71 
77  bool End();
78 
82  bool GetBufferIdMode() const;
83 
91 
99 
103  void DrawLine(float x1, float y1, float x2, float y2);
104 
108  void DrawLine(float p[4]);
109 
115 
119  void DrawPoly(float* x, float* y, int n);
120 
126 
132  void DrawPoly(float* points, int n);
133 
140  void DrawPoly(float* points, int n, unsigned char* colors, int nc_comps);
141 
147 
152  void DrawLines(float* points, int n);
153 
157  void DrawPoint(float x, float y);
158 
162  void DrawPoints(float* x, float* y, int n);
163 
169 
175  void DrawPoints(float* points, int n);
176 
183 
185 
193  vtkImageData* sprite, float* points, int n, unsigned char* colors, int nc_comps);
195 
201  void DrawPointSprites(vtkImageData* sprite, float* points, int n);
202 
204 
216  virtual void DrawMarkers(
217  int shape, bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
218  virtual void DrawMarkers(int shape, bool highlight, float* points, int n);
219  virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D* points);
220  virtual void DrawMarkers(
221  int shape, bool highlight, vtkPoints2D* points, vtkUnsignedCharArray* colors);
223 
227  void DrawRect(float x, float y, float w, float h);
228 
230 
233  void DrawQuad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);
234  void DrawQuad(float* p);
236 
238 
242  void DrawQuadStrip(float* p, int n);
244 
249  void DrawPolygon(float* x, float* y, int n);
250 
256 
262  void DrawPolygon(float* points, int n);
263 
268  void DrawPolygon(float* x, float* y, int n, unsigned char* color, int nc_comps);
269 
274  void DrawPolygon(vtkPoints2D* points, unsigned char* color, int nc_comps);
275 
281  void DrawPolygon(float* points, int n, unsigned char* color, int nc_comps);
282 
288  void DrawEllipse(float x, float y, float rx, float ry);
289 
298  void DrawWedge(
299  float x, float y, float outRadius, float inRadius, float startAngle, float stopAngle);
300 
312  void DrawEllipseWedge(float x, float y, float outRx, float outRy, float inRx, float inRy,
313  float startAngle, float stopAngle);
314 
320  void DrawArc(float x, float y, float r, float startAngle, float stopAngle);
321 
328  void DrawEllipticArc(float x, float y, float rX, float rY, float startAngle, float stopAngle);
329 
333  void DrawImage(float x, float y, vtkImageData* image);
334 
339  void DrawImage(float x, float y, float scale, vtkImageData* image);
340 
346  void DrawImage(const vtkRectf& pos, vtkImageData* image);
347 
353  float x, float y, vtkPolyData* polyData, vtkUnsignedCharArray* colors, int scalarMode);
354 
356 
361  void DrawStringRect(vtkPoints2D* rect, const vtkStdString& string);
362  void DrawStringRect(vtkPoints2D* rect, const vtkUnicodeString& string);
363  void DrawStringRect(vtkPoints2D* rect, const char* string);
365 
367 
370  void DrawString(vtkPoints2D* point, const vtkStdString& string);
371  void DrawString(float x, float y, const vtkStdString& string);
373  void DrawString(float x, float y, const vtkUnicodeString& string);
374  void DrawString(vtkPoints2D* point, const char* string);
375  void DrawString(float x, float y, const char* string);
377 
379 
388  void ComputeStringBounds(const vtkStdString& string, vtkPoints2D* bounds);
389  void ComputeStringBounds(const vtkStdString& string, float bounds[4]);
390  void ComputeStringBounds(const vtkUnicodeString& string, vtkPoints2D* bounds);
391  void ComputeStringBounds(const vtkUnicodeString& string, float bounds[4]);
392  void ComputeStringBounds(const char* string, vtkPoints2D* bounds);
393  void ComputeStringBounds(const char* string, float bounds[4]);
395 
400  void ComputeJustifiedStringBounds(const char* string, float bounds[4]);
401 
408  int ComputeFontSizeForBoundedString(const vtkStdString& string, float width, float height);
409 
411 
419  void DrawMathTextString(float x, float y, const vtkStdString& string);
420  void DrawMathTextString(vtkPoints2D* point, const char* string);
421  void DrawMathTextString(float x, float y, const char* string);
423 
425 
434  vtkPoints2D* point, const vtkStdString& string, const vtkStdString& fallback);
436  float x, float y, const vtkStdString& string, const vtkStdString& fallback);
437  void DrawMathTextString(vtkPoints2D* point, const char* string, const char* fallback);
438  void DrawMathTextString(float x, float y, const char* string, const char* fallback);
440 
445 
451  void ApplyPen(vtkPen* pen);
452 
459 
465  void ApplyBrush(vtkBrush* brush);
466 
472 
479 
484 
490  void SetTransform(vtkTransform2D* transform);
491 
496 
503  void AppendTransform(vtkTransform2D* transform);
504 
506 
510  void PushMatrix();
511  void PopMatrix();
513 
517  void ApplyId(vtkIdType id);
518 
524  static int FloatToInt(float x);
525 
527 
531  vtkGetObjectMacro(Context3D, vtkContext3D);
532  virtual void SetContext3D(vtkContext3D* context);
534 
535 protected:
537  ~vtkContext2D() override;
538 
539  vtkContextDevice2D* Device; // The underlying device
540  vtkTransform2D* Transform; // Current transform
541 
543  vtkContext3D* Context3D; // May be very temporary - get at a 3D version.
544 
545 private:
546  vtkContext2D(const vtkContext2D&) = delete;
547  void operator=(const vtkContext2D&) = delete;
548 
555  vtkVector2f CalculateTextPosition(vtkPoints2D* rect);
556 
563  vtkVector2f CalculateTextPosition(float rect[4]);
564 };
565 
566 inline int vtkContext2D::FloatToInt(float x)
567 {
568  // Use a tolerance of 1/256 of a pixel when converting.
569  // A float has only 24 bits of precision, so we cannot
570  // make the tolerance too small. For example, a tolerance
571  // of 2^-8 means that the tolerance will be significant
572  // for float values up to 2^16 or 65536.0. But a
573  // tolerance of 2^-16 would only be significant for
574  // float values up to 2^8 or 256.0. A small tolerance
575  // disappears into insignificance when added to a large float.
576  float tol = 0.00390625; // 1.0/256.0
577  tol = (x >= 0 ? tol : -tol);
578  return static_cast<int>(x + tol);
579 }
580 
581 #endif // vtkContext2D_h
vtkBrush
provides a brush that fills shapes drawn by vtkContext2D.
Definition: vtkBrush.h:38
vtkPoints2D
represent and manipulate 2D points
Definition: vtkPoints2D.h:34
vtkContext2D::DrawPolyData
void DrawPolyData(float x, float y, vtkPolyData *polyData, vtkUnsignedCharArray *colors, int scalarMode)
Draw the supplied polyData at the given x, y position (bottom corner).
vtkContext2D::DrawWedge
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...
vtkContext2D::DrawArc
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...
vtkContext2D::DrawPolygon
void DrawPolygon(vtkPoints2D *points)
Draw a polygon defined by the specified points - fastest code path due to memory layout of the coordi...
vtkContext2D::DrawPolygon
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...
vtkContext2D::DrawPoints
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...
vtkContext2D::DrawQuad
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).
vtkContext2D::SetContext3D
virtual void SetContext3D(vtkContext3D *context)
vtkContext2D::DrawMathTextString
void DrawMathTextString(vtkPoints2D *point, const vtkStdString &string, const vtkStdString &fallback)
Draw a MathText formatted equation to the screen.
vtkContext2D::DrawLine
void DrawLine(float x1, float y1, float x2, float y2)
Draw a line between the specified points.
vtkContext2D::ComputeStringBounds
void ComputeStringBounds(const vtkStdString &string, vtkPoints2D *bounds)
Compute the bounds of the supplied string.
vtkContext2D::DrawStringRect
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...
vtkX3D::scale
@ scale
Definition: vtkX3D.h:235
vtkContext2D::DrawPolygon
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...
vtkContext2D::ApplyPen
void ApplyPen(vtkPen *pen)
Apply the supplied pen which controls the outlines of shapes, as well as lines, points and related pr...
vtkIdType
int vtkIdType
Definition: vtkType.h:338
vtkContext2D::DrawString
void DrawString(vtkPoints2D *point, const char *string)
vtkContext2D::PopMatrix
void PopMatrix()
vtkContext2D::New
static vtkContext2D * New()
Creates a 2D Painter object.
vtkTransform2D
describes linear transformations via a 3x3 matrix
Definition: vtkTransform2D.h:46
vtkContext2D::DrawLines
void DrawLines(vtkPoints2D *points)
Draw multiple lines between the specified pairs of points.
vtkContext2D::DrawPoly
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...
vtkContext2D::DrawString
void DrawString(vtkPoints2D *point, const vtkUnicodeString &string)
vtkX3D::image
@ image
Definition: vtkX3D.h:380
vtkContext2D::DrawMarkers
virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D *points)
vtkUnsignedCharArray
dynamic, self-adjusting array of unsigned char
Definition: vtkUnsignedCharArray.h:36
vtkContext2D::DrawMathTextString
void DrawMathTextString(float x, float y, const vtkStdString &string, const vtkStdString &fallback)
vtkContext2D::BufferId
vtkAbstractContextBufferId * BufferId
Definition: vtkContext2D.h:542
vtkContext2D::DrawEllipticArc
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 ...
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:54
vtkContext2D::ComputeFontSizeForBoundedString
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...
vtkContext2D::ApplyId
void ApplyId(vtkIdType id)
Apply id as a color.
vtkContext2D::DrawMathTextString
void DrawMathTextString(float x, float y, const char *string)
vtkContext2D::DrawPoint
void DrawPoint(float x, float y)
Draw a point at the supplied x and y coordinate.
vtkContext2D
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:53
vtkContext2D::ComputeStringBounds
void ComputeStringBounds(const vtkUnicodeString &string, vtkPoints2D *bounds)
vtkContext2D::ApplyBrush
void ApplyBrush(vtkBrush *brush)
Apply the supplied brush which controls the outlines of shapes, as well as lines, points and related ...
vtkContext2D::MathTextIsSupported
bool MathTextIsSupported()
Return true if MathText rendering available on the current device.
vtkContext2D::DrawLine
void DrawLine(float p[4])
Draw a line between the specified points.
vtkContext2D::SetTransform
void SetTransform(vtkTransform2D *transform)
Set the transform for the context, the underlying device will use the matrix of the transform.
vtkContext2D::ComputeStringBounds
void ComputeStringBounds(const char *string, float bounds[4])
vtkContext2D::DrawPoints
void DrawPoints(vtkPoints2D *points)
Draw a poly line between the specified points - fastest code path due to memory layout of the coordin...
vtkContext2D::DrawStringRect
void DrawStringRect(vtkPoints2D *rect, const char *string)
vtkContext2D::GetTransform
vtkTransform2D * GetTransform()
Compute the current transform applied to the context.
vtkWindow
window superclass for vtkRenderWindow
Definition: vtkWindow.h:35
vtkContext2D::Begin
bool Begin(vtkContextDevice2D *device)
Begin painting on a vtkContextDevice2D, no painting can occur before this call has been made.
vtkContext2D::DrawMathTextString
void DrawMathTextString(float x, float y, const char *string, const char *fallback)
vtkContext2D::DrawRect
void DrawRect(float x, float y, float w, float h)
Draw a rectangle with origin at x, y and width w, height h.
vtkContext2D::Transform
vtkTransform2D * Transform
Definition: vtkContext2D.h:540
vtkAbstractContextBufferId
2D array of ids, used for picking.
Definition: vtkAbstractContextBufferId.h:47
vtkContext2D::DrawString
void DrawString(float x, float y, const vtkStdString &string)
vtkContext2D::Context3D
vtkContext3D * Context3D
Definition: vtkContext2D.h:543
vtkX3D::color
@ color
Definition: vtkX3D.h:227
vtkX3D::points
@ points
Definition: vtkX3D.h:452
vtkX3D::point
@ point
Definition: vtkX3D.h:242
vtkContext2D::ComputeStringBounds
void ComputeStringBounds(const vtkStdString &string, float bounds[4])
vtkContext2D::DrawLine
void DrawLine(vtkPoints2D *points)
Draw a line between the specified points.
vtkContext2D::DrawQuadStrip
void DrawQuadStrip(vtkPoints2D *points)
Draw a strip of quads.
vtkContext2D::DrawLines
void DrawLines(float *points, int n)
Draw multiple lines between the specified pairs of points.
vtkContext2D::Device
vtkContextDevice2D * Device
Definition: vtkContext2D.h:539
vtkContext2D::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkX3D::height
@ height
Definition: vtkX3D.h:260
vtkContext2D::DrawPolygon
void DrawPolygon(float *x, float *y, int n)
Draw a polygon specified specified by the points using the x and y arrays supplied.
vtkContext2D::DrawPoints
void DrawPoints(float *x, float *y, int n)
Draw the specified number of points using the x and y arrays supplied.
vtkContext2D::FloatToInt
static int FloatToInt(float x)
Float to int conversion, performs truncation but with a rounding tolerance for float values that are ...
Definition: vtkContext2D.h:566
vtkContext2D::DrawPoly
void DrawPoly(vtkPoints2D *points)
Draw a poly line between the specified points - fastest code path due to memory layout of the coordin...
vtkContext2D::DrawEllipseWedge
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::DrawMathTextString
void DrawMathTextString(vtkPoints2D *point, const char *string, const char *fallback)
vtkContext2D::GetTextProp
vtkTextProperty * GetTextProp()
Get the text properties object for the vtkContext2D.
vtkContext2D::DrawPoly
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...
vtkContext2D::DrawString
void DrawString(float x, float y, const vtkUnicodeString &string)
vtkContext2D::DrawMarkers
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.
vtkImageData
topologically and geometrically regular array of data
Definition: vtkImageData.h:42
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:34
vtkUnicodeString
String class that stores Unicode text.
Definition: vtkUnicodeString.h:70
vtkContext2D::DrawPolygon
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...
vtkContext2D::DrawString
void DrawString(vtkPoints2D *point, const vtkStdString &string)
Draw some text to the screen.
vtkContext2D::~vtkContext2D
~vtkContext2D() override
vtkContext2D::AppendTransform
void AppendTransform(vtkTransform2D *transform)
Append the transform for the context, the underlying device will use the matrix of the transform.
vtkContext2D::DrawMarkers
virtual void DrawMarkers(int shape, bool highlight, float *points, int n)
vtkX3D::startAngle
@ startAngle
Definition: vtkX3D.h:492
vtkContext2D::DrawMarkers
virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D *points, vtkUnsignedCharArray *colors)
vtkContext2D::DrawImage
void DrawImage(float x, float y, vtkImageData *image)
Draw the supplied image at the given x, y location (bottom corner).
vtkContext2D::BufferIdModeEnd
void BufferIdModeEnd()
Finalize BufferId creation Mode.
vtkObject.h
vtkContext2D::DrawMathTextString
void DrawMathTextString(float x, float y, const vtkStdString &string)
vtkContextDevice2D
Abstract class for drawing 2D primitives.
Definition: vtkContextDevice2D.h:51
vtkTextProperty
represent text properties.
Definition: vtkTextProperty.h:34
vtkContext2D::DrawEllipse
void DrawEllipse(float x, float y, float rx, float ry)
Draw an ellipse with center at x, y and radii rx, ry.
vtkContext2D::GetBrush
vtkBrush * GetBrush()
Get the pen which controls the outlines of shapes as well as lines, points and related primitives.
vtkContext2D::ComputeJustifiedStringBounds
void ComputeJustifiedStringBounds(const char *string, float bounds[4])
Compute the bounds of the supplied string while taking into account the justification and rotation of...
vtkContext2D::GetPen
vtkPen * GetPen()
Get the pen which controls the outlines of shapes, as well as lines, points and related primitives.
vtkContext2D::DrawMathTextString
void DrawMathTextString(vtkPoints2D *point, const char *string)
vtkContext2D::ComputeStringBounds
void ComputeStringBounds(const char *string, vtkPoints2D *bounds)
vtkContext2D::DrawPointSprites
void DrawPointSprites(vtkImageData *sprite, vtkPoints2D *points)
Draw a series of point sprites, images centred at the points supplied.
vtkPolyData
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:85
vtkContext2D::DrawStringRect
void DrawStringRect(vtkPoints2D *rect, const vtkUnicodeString &string)
vtkContext2D::DrawString
void DrawString(float x, float y, const char *string)
vtkContext3D
Class for drawing 3D primitives to a graphical context.
Definition: vtkContext3D.h:41
vtkContext2D::DrawMathTextString
void DrawMathTextString(vtkPoints2D *point, const vtkStdString &string)
Draw a MathText formatted equation to the screen.
vtkContext2D::vtkContext2D
vtkContext2D()
vtkPen
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:37
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:35
vtkContext2D::ApplyTextProp
void ApplyTextProp(vtkTextProperty *prop)
Apply the supplied text property which controls how text is rendered.
vtkContext2D::ComputeStringBounds
void ComputeStringBounds(const vtkUnicodeString &string, float bounds[4])
vtkContext2D::DrawQuad
void DrawQuad(float *p)
vtkContext2D::DrawPointSprites
void DrawPointSprites(vtkImageData *sprite, vtkPoints2D *points, vtkUnsignedCharArray *colors)
Draw a series of point sprites, images centred at the points supplied.
vtkContext2D::DrawQuadStrip
void DrawQuadStrip(float *p, int n)
vtkContext2D::DrawPolygon
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.
vtkContext2D::DrawPoly
void DrawPoly(float *x, float *y, int n)
Draw a poly line between the specified points.
vtkContext2D::DrawImage
void DrawImage(float x, float y, float scale, vtkImageData *image)
Draw the supplied image at the given x, y location (bottom corner).
vtkContext2D::GetBufferIdMode
bool GetBufferIdMode() const
Tell if the context is in BufferId creation mode.
vtkRectf
Definition: vtkRect.h:327
vtkContext2D::DrawPointSprites
void DrawPointSprites(vtkImageData *sprite, float *points, int n, unsigned char *colors, int nc_comps)
vtkContext2D::DrawImage
void DrawImage(const vtkRectf &pos, vtkImageData *image)
Draw the supplied image at the given position.
vtkVector2f
Definition: vtkVector.h:433
h
vtkFrustumSelector is a vtkSelector that selects elements based on whether they are inside or interse...
vtkContext2D::DrawPointSprites
void DrawPointSprites(vtkImageData *sprite, float *points, int n)
Draw a series of point sprites, images centred at the points supplied.
vtkContext2D::PushMatrix
void PushMatrix()
Push/pop the transformation matrix for the painter (sets the underlying matrix for the device when av...
vtkContext2D::End
bool End()
Ends painting on the device, you would not usually need to call this as it should be called by the de...
vtkContext2D::BufferIdModeBegin
void BufferIdModeBegin(vtkAbstractContextBufferId *bufferId)
Start BufferId creation Mode.