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 
39 class vtkWindow;
40 
41 class vtkContext3D;
42 class vtkStdString;
43 class vtkUnicodeString;
44 class vtkTextProperty;
45 
46 class vtkPoints2D;
47 class vtkVector2f;
48 class vtkRectf;
50 class vtkContextDevice2D;
51 class vtkPen;
52 class vtkBrush;
53 class vtkImageData;
54 class vtkPolyData;
55 class vtkTransform2D;
57 
58 class VTKRENDERINGCONTEXT2D_EXPORT vtkContext2D : public vtkObject
59 {
60 public:
61  vtkTypeMacro(vtkContext2D, vtkObject);
62  void PrintSelf(ostream &os, vtkIndent indent) override;
63 
67  static vtkContext2D *New();
68 
74  bool Begin(vtkContextDevice2D *device);
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 
121 
125  void DrawPoly(float *x, float *y, int n);
126 
132 
138  void DrawPoly(float *points, int n);
139 
146  void DrawPoly(float *points, int n,
147  unsigned char *colors, int nc_comps);
148 
154 
159  void DrawLines(float *points, int n);
160 
164  void DrawPoint(float x, float y);
165 
169  void DrawPoints(float *x, float *y, int n);
170 
176 
182  void DrawPoints(float *points, int n);
183 
190 
192 
199  vtkUnsignedCharArray *colors);
200  void DrawPointSprites(vtkImageData *sprite, float *points, int n,
201  unsigned char *colors, int nc_comps);
203 
209  void DrawPointSprites(vtkImageData *sprite, float *points, int n);
210 
212 
224  virtual void DrawMarkers(int shape, bool highlight, float *points, int n,
225  unsigned char *colors, int nc_comps);
226  virtual void DrawMarkers(int shape, bool highlight, float *points, int n);
227  virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D *points);
228  virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D *points,
229  vtkUnsignedCharArray *colors);
231 
235  void DrawRect(float x, float y, float w, float h);
236 
238 
241  void DrawQuad(float x1, float y1, float x2, float y2,
242  float x3, float y3, float x4, float y4);
243  void DrawQuad(float *p);
245 
247 
251  void DrawQuadStrip(float *p, int n);
253 
258  void DrawPolygon(float *x, float *y, int n);
259 
265 
271  void DrawPolygon(float *points, int n);
272 
277  void DrawPolygon(float *x, float *y, int n,
278  unsigned char *color, int nc_comps);
279 
285  unsigned char *color, int nc_comps);
286 
292  void DrawPolygon(float *points, int n,
293  unsigned char *color, int nc_comps);
294 
300  void DrawEllipse(float x, float y, float rx, float ry);
301 
310  void DrawWedge(float x, float y, float outRadius,
311  float inRadius,float startAngle,
312  float stopAngle);
313 
325  void DrawEllipseWedge(float x, float y, float outRx, float outRy,
326  float inRx, float inRy, float startAngle,
327  float stopAngle);
328 
329 
335  void DrawArc(float x, float y, float r, float startAngle,
336  float stopAngle);
337 
344  void DrawEllipticArc(float x, float y, float rX, float rY, float startAngle,
345  float stopAngle);
346 
347 
351  void DrawImage(float x, float y, vtkImageData *image);
352 
357  void DrawImage(float x, float y, float scale, vtkImageData *image);
358 
364  void DrawImage(const vtkRectf& pos, vtkImageData *image);
365 
370  void DrawPolyData(float x, float y, vtkPolyData* polyData,
371  vtkUnsignedCharArray* colors, int scalarMode);
372 
374 
379  void DrawStringRect(vtkPoints2D *rect, const vtkStdString &string);
380  void DrawStringRect(vtkPoints2D *rect, const vtkUnicodeString &string);
381  void DrawStringRect(vtkPoints2D *rect, const char* string);
383 
385 
388  void DrawString(vtkPoints2D *point, const vtkStdString &string);
389  void DrawString(float x, float y, const vtkStdString &string);
391  void DrawString(float x, float y, const vtkUnicodeString &string);
392  void DrawString(vtkPoints2D *point, const char* string);
393  void DrawString(float x, float y, const char* string);
395 
397 
406  void ComputeStringBounds(const vtkStdString &string, vtkPoints2D *bounds);
407  void ComputeStringBounds(const vtkStdString &string, float bounds[4]);
408  void ComputeStringBounds(const vtkUnicodeString &string, vtkPoints2D *bounds);
409  void ComputeStringBounds(const vtkUnicodeString &string, float bounds[4]);
410  void ComputeStringBounds(const char* string, vtkPoints2D *bounds);
411  void ComputeStringBounds(const char* string, float bounds[4]);
413 
418  void ComputeJustifiedStringBounds(const char* string, float bounds[4]);
419 
426  int ComputeFontSizeForBoundedString(const vtkStdString &string, float width,
427  float height);
428 
430 
438  void DrawMathTextString(float x, float y, const vtkStdString &string);
439  void DrawMathTextString(vtkPoints2D *point, const char *string);
440  void DrawMathTextString(float x, float y, const char *string);
442 
444 
453  const vtkStdString &fallback);
454  void DrawMathTextString(float x, float y, const vtkStdString &string,
455  const vtkStdString &fallback);
456  void DrawMathTextString(vtkPoints2D *point, const char *string,
457  const char *fallback);
458  void DrawMathTextString(float x, float y, const char *string,
459  const char *fallback);
461 
462 
467 
473  void ApplyPen(vtkPen *pen);
474 
481 
487  void ApplyBrush(vtkBrush *brush);
488 
494 
501 
506 
512  void SetTransform(vtkTransform2D *transform);
513 
518 
525  void AppendTransform(vtkTransform2D *transform);
526 
528 
532  void PushMatrix();
533  void PopMatrix();
535 
539  void ApplyId(vtkIdType id);
540 
546  static int FloatToInt(float x);
547 
549 
553  vtkGetObjectMacro(Context3D, vtkContext3D)
554  virtual void SetContext3D(vtkContext3D *context);
556 
557 protected:
559  ~vtkContext2D() override;
560 
561  vtkContextDevice2D *Device; // The underlying device
562  vtkTransform2D *Transform; // Current transform
563 
565  vtkContext3D *Context3D; // May be very temporary - get at a 3D version.
566 
567 private:
568  vtkContext2D(const vtkContext2D &) = delete;
569  void operator=(const vtkContext2D &) = delete;
570 
577  vtkVector2f CalculateTextPosition(vtkPoints2D* rect);
578 
585  vtkVector2f CalculateTextPosition(float rect[4]);
586 
587 };
588 
589 inline int vtkContext2D::FloatToInt(float x)
590 {
591  // Use a tolerance of 1/256 of a pixel when converting.
592  // A float has only 24 bits of precision, so we cannot
593  // make the tolerance too small. For example, a tolerance
594  // of 2^-8 means that the tolerance will be significant
595  // for float values up to 2^16 or 65536.0. But a
596  // tolerance of 2^-16 would only be significant for
597  // float values up to 2^8 or 256.0. A small tolerance
598  // disappears into insignificance when added to a large float.
599  float tol = 0.00390625; // 1.0/256.0
600  tol = (x >= 0 ? tol : -tol);
601  return static_cast<int>(x + tol);
602 }
603 
604 #endif //vtkContext2D_h
vtkBrush
provides a brush that fills shapes drawn by vtkContext2D.
Definition: vtkBrush.h:41
vtkPoints2D
represent and manipulate 2D points
Definition: vtkPoints2D.h:37
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::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:229
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:347
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:52
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:374
vtkContext2D::DrawMarkers
virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D *points)
vtkUnsignedCharArray
dynamic, self-adjusting array of unsigned char
Definition: vtkUnsignedCharArray.h:42
vtkContext2D::DrawMathTextString
void DrawMathTextString(float x, float y, const vtkStdString &string, const vtkStdString &fallback)
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:60
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:59
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:38
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.
vtkAbstractContextBufferId
2D array of ids, used for picking.
Definition: vtkAbstractContextBufferId.h:47
vtkContext2D::DrawString
void DrawString(float x, float y, const vtkStdString &string)
vtkX3D::color
@ color
Definition: vtkX3D.h:221
vtkX3D::points
@ points
Definition: vtkX3D.h:446
vtkX3D::point
@ point
Definition: vtkX3D.h:236
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::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:254
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.
ADIOS::Transform
Transform
Definition: ADIOSDefs.h:41
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:46
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:40
vtkUnicodeString
String class that stores Unicode text.
Definition: vtkUnicodeString.h:73
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::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:486
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:54
vtkTextProperty
represent text properties.
Definition: vtkTextProperty.h:40
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:86
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.
vtkPen
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:40
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:41
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:333
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:419
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.