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 
46 #ifndef vtkContext2D_h
47 #define vtkContext2D_h
48 
49 #include "vtkDeprecation.h" // for deprecation macros
50 #include "vtkObject.h"
51 #include "vtkRenderingContext2DModule.h" // For export macro
52 
53 class vtkWindow;
54 
55 class vtkContext3D;
56 class vtkStdString;
57 class vtkUnicodeString;
58 class vtkTextProperty;
59 
60 class vtkPoints2D;
61 class vtkVector2f;
62 class vtkRectf;
64 class vtkContextDevice2D;
65 class vtkPen;
66 class vtkBrush;
67 class vtkImageData;
68 class vtkPolyData;
69 class vtkTransform2D;
71 
72 class VTKRENDERINGCONTEXT2D_EXPORT vtkContext2D : public vtkObject
73 {
74 public:
75  vtkTypeMacro(vtkContext2D, vtkObject);
76  void PrintSelf(ostream& os, vtkIndent indent) override;
77 
81  static vtkContext2D* New();
82 
88  bool Begin(vtkContextDevice2D* device);
89 
90  vtkGetObjectMacro(Device, vtkContextDevice2D);
91 
97  bool End();
98 
102  bool GetBufferIdMode() const;
103 
111 
119 
123  void DrawLine(float x1, float y1, float x2, float y2);
124 
128  void DrawLine(float p[4]);
129 
135 
139  void DrawPoly(float* x, float* y, int n);
140 
146 
152  void DrawPoly(float* points, int n);
153 
160  void DrawPoly(float* points, int n, unsigned char* colors, int nc_comps);
161 
167 
172  void DrawLines(float* points, int n);
173 
177  void DrawPoint(float x, float y);
178 
182  void DrawPoints(float* x, float* y, int n);
183 
189 
195  void DrawPoints(float* points, int n);
196 
203 
205 
213  vtkImageData* sprite, float* points, int n, unsigned char* colors, int nc_comps);
215 
221  void DrawPointSprites(vtkImageData* sprite, float* points, int n);
222 
224 
240  virtual void DrawMarkers(
241  int shape, bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
242  virtual void DrawMarkers(int shape, bool highlight, float* points, int n);
243  virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D* points);
244  virtual void DrawMarkers(
245  int shape, bool highlight, vtkPoints2D* points, vtkUnsignedCharArray* colors);
247 
251  void DrawRect(float x, float y, float w, float h);
252 
254 
257  void DrawQuad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);
258  void DrawQuad(float* p);
260 
262 
266  void DrawQuadStrip(float* p, int n);
268 
273  void DrawPolygon(float* x, float* y, int n);
274 
280 
286  void DrawPolygon(float* points, int n);
287 
292  void DrawPolygon(float* x, float* y, int n, unsigned char* color, int nc_comps);
293 
298  void DrawPolygon(vtkPoints2D* points, unsigned char* color, int nc_comps);
299 
305  void DrawPolygon(float* points, int n, unsigned char* color, int nc_comps);
306 
312  void DrawEllipse(float x, float y, float rx, float ry);
313 
322  void DrawWedge(
323  float x, float y, float outRadius, float inRadius, float startAngle, float stopAngle);
324 
336  void DrawEllipseWedge(float x, float y, float outRx, float outRy, float inRx, float inRy,
337  float startAngle, float stopAngle);
338 
344  void DrawArc(float x, float y, float r, float startAngle, float stopAngle);
345 
352  void DrawEllipticArc(float x, float y, float rX, float rY, float startAngle, float stopAngle);
353 
357  void DrawImage(float x, float y, vtkImageData* image);
358 
363  void DrawImage(float x, float y, float scale, vtkImageData* image);
364 
370  void DrawImage(const vtkRectf& pos, vtkImageData* image);
371 
377  float x, float y, vtkPolyData* polyData, vtkUnsignedCharArray* colors, int scalarMode);
378 
380 
385  void DrawStringRect(vtkPoints2D* rect, const vtkStdString& string);
386  VTK_DEPRECATED_IN_9_1_0("Use void DrawStringRect(vtkPoints2D* rect, const vtkStdString& string)")
387  void DrawStringRect(vtkPoints2D* rect, const vtkUnicodeString& string);
388  void DrawStringRect(vtkPoints2D* rect, const char* string);
389  void DrawStringRect(const float rect[4], const vtkStdString& string);
391  "Use void DrawStringRect(const float rect[4], const vtkStdString& string)")
392  void DrawStringRect(const float rect[4], const vtkUnicodeString& string);
393  void DrawStringRect(const float rect[4], const char* string);
395 
397 
400  void DrawString(vtkPoints2D* point, const vtkStdString& string);
401  void DrawString(float x, float y, const vtkStdString& string);
402  VTK_DEPRECATED_IN_9_1_0("Use void DrawString(vtkPoints2D* point, const vtkStdString& string)")
403  void DrawString(vtkPoints2D* point, const vtkUnicodeString& string);
404  VTK_DEPRECATED_IN_9_1_0("Use void DrawString(float x, float y, const vtkStdString& string)")
405  void DrawString(float x, float y, const vtkUnicodeString& string);
406  void DrawString(vtkPoints2D* point, const char* string);
407  void DrawString(float x, float y, const char* string);
409 
411 
420  void ComputeStringBounds(const vtkStdString& string, vtkPoints2D* bounds);
421  void ComputeStringBounds(const vtkStdString& string, float bounds[4]);
423  "Use void ComputeStringBounds(const vtkStdString& string, vtkPoints2D* bounds)")
424  void ComputeStringBounds(const vtkUnicodeString& string, vtkPoints2D* bounds);
426  "Use void ComputeStringBounds(const vtkStdString& string, float bounds[4])")
427  void ComputeStringBounds(const vtkUnicodeString& string, float bounds[4]);
428  void ComputeStringBounds(const char* string, vtkPoints2D* bounds);
429  void ComputeStringBounds(const char* string, float bounds[4]);
431 
436  void ComputeJustifiedStringBounds(const char* string, float bounds[4]);
437 
444  int ComputeFontSizeForBoundedString(const vtkStdString& string, float width, float height);
445 
447 
454  void DrawMathTextString(vtkPoints2D* point, const vtkStdString& string);
455  void DrawMathTextString(float x, float y, const vtkStdString& string);
456  void DrawMathTextString(vtkPoints2D* point, const char* string);
457  void DrawMathTextString(float x, float y, const char* string);
459 
461 
469  void DrawMathTextString(
470  vtkPoints2D* point, const vtkStdString& string, const vtkStdString& fallback);
471  void DrawMathTextString(
472  float x, float y, const vtkStdString& string, const vtkStdString& fallback);
473  void DrawMathTextString(vtkPoints2D* point, const char* string, const char* fallback);
474  void DrawMathTextString(float x, float y, const char* string, const char* fallback);
476 
480  bool MathTextIsSupported();
481 
487  void ApplyPen(vtkPen* pen);
488 
494  vtkPen* GetPen();
495 
501  void ApplyBrush(vtkBrush* brush);
502 
507  vtkBrush* GetBrush();
508 
514  void ApplyTextProp(vtkTextProperty* prop);
515 
519  vtkTextProperty* GetTextProp();
520 
526  void SetTransform(vtkTransform2D* transform);
527 
531  vtkTransform2D* GetTransform();
532 
539  void AppendTransform(vtkTransform2D* transform);
540 
542 
546  void PushMatrix();
547  void PopMatrix();
549 
553  void ApplyId(vtkIdType id);
554 
560  static int FloatToInt(float x);
561 
563 
567  vtkGetObjectMacro(Context3D, vtkContext3D);
568  virtual void SetContext3D(vtkContext3D* context);
570 
571 protected:
573  ~vtkContext2D() override;
574 
575  vtkContextDevice2D* Device; // The underlying device
576  vtkTransform2D* Transform; // Current transform
577 
579  vtkContext3D* Context3D; // May be very temporary - get at a 3D version.
580 
581 private:
582  vtkContext2D(const vtkContext2D&) = delete;
583  void operator=(const vtkContext2D&) = delete;
584 
591  vtkVector2f CalculateTextPosition(vtkPoints2D* rect);
592 
599  vtkVector2f CalculateTextPosition(const float rect[4]);
600 };
601 
602 inline int vtkContext2D::FloatToInt(float x)
603 {
604  // Use a tolerance of 1/256 of a pixel when converting.
605  // A float has only 24 bits of precision, so we cannot
606  // make the tolerance too small. For example, a tolerance
607  // of 2^-8 means that the tolerance will be significant
608  // for float values up to 2^16 or 65536.0. But a
609  // tolerance of 2^-16 would only be significant for
610  // float values up to 2^8 or 256.0. A small tolerance
611  // disappears into insignificance when added to a large float.
612  float tol = 0.00390625; // 1.0/256.0
613  tol = (x >= 0 ? tol : -tol);
614  return static_cast<int>(x + tol);
615 }
616 
617 #endif // vtkContext2D_h
vtkBrush
provides a brush that fills shapes drawn by vtkContext2D.
Definition: vtkBrush.h:97
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::DrawLine
void DrawLine(float x1, float y1, float x2, float y2)
Draw a line between the specified points.
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...
vtkIdType
int vtkIdType
Definition: vtkType.h:332
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...
vtkX3D::image
@ image
Definition: vtkX3D.h:380
vtkContext2D::DrawMarkers
virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D *points)
Draw a series of markers centered at the points supplied.
vtkUnsignedCharArray
dynamic, self-adjusting array of unsigned char
Definition: vtkUnsignedCharArray.h:145
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:82
VTK_DEPRECATED_IN_9_1_0
#define VTK_DEPRECATED_IN_9_1_0(reason)
Definition: vtkDeprecation.h:117
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:73
vtkContext2D::DrawLine
void DrawLine(float p[4])
Draw a line between the specified points.
vtkContext2D::DrawPoints
void DrawPoints(vtkPoints2D *points)
Draw a poly line between the specified points - fastest code path due to memory layout of the coordin...
vtkX3D::Transform
@ Transform
Definition: vtkX3D.h:47
vtkWindow
window superclass for vtkRenderWindow
Definition: vtkWindow.h:39
vtkContext2D::Begin
bool Begin(vtkContextDevice2D *device)
Begin painting on a vtkContextDevice2D, no painting can occur before this call has been made.
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
vtkX3D::color
@ color
Definition: vtkX3D.h:227
vtkX3D::points
@ points
Definition: vtkX3D.h:452
vtkX3D::point
@ point
Definition: vtkX3D.h:242
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: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::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::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::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:157
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:113
vtkUnicodeString
String class that stores Unicode text.
Definition: vtkUnicodeString.h:80
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::DrawMarkers
virtual void DrawMarkers(int shape, bool highlight, float *points, int n)
Draw a series of markers centered at the points supplied.
vtkX3D::startAngle
@ startAngle
Definition: vtkX3D.h:492
vtkContext2D::DrawMarkers
virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D *points, vtkUnsignedCharArray *colors)
Draw a series of markers centered at the points supplied.
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
vtkContextDevice2D
Abstract class for drawing 2D primitives.
Definition: vtkContextDevice2D.h:52
vtkTextProperty
represent text properties.
Definition: vtkTextProperty.h:143
vtkContext2D::DrawEllipse
void DrawEllipse(float x, float y, float rx, float ry)
Draw an ellipse with center at x, y and radii rx, ry.
vtkDeprecation.h
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:195
vtkContext3D
Class for drawing 3D primitives to a graphical context.
Definition: vtkContext3D.h:60
vtkPen
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:136
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:105
vtkContext2D::DrawQuad
void DrawQuad(float *p)
Draw a quadrilateral at the specified points (4 points, 8 floats in x, y).
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)
Draw a strip of quads.
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:336
vtkContext2D::DrawPointSprites
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.
vtkContext2D::DrawImage
void DrawImage(const vtkRectf &pos, vtkImageData *image)
Draw the supplied image at the given position.
vtkVector2f
Definition: vtkVector.h:491
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::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.