VTK  9.0.20210409
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 
34 class vtkWindow;
35 
36 class vtkContext3D;
37 class vtkStdString;
38 class vtkUnicodeString;
39 class vtkTextProperty;
40 
41 class vtkPoints2D;
42 class vtkVector2f;
43 class vtkRectf;
45 class vtkContextDevice2D;
46 class vtkPen;
47 class vtkBrush;
48 class vtkImageData;
49 class vtkPolyData;
50 class vtkTransform2D;
52 
53 class VTKRENDERINGCONTEXT2D_EXPORT vtkContext2D : public vtkObject
54 {
55 public:
56  vtkTypeMacro(vtkContext2D, vtkObject);
57  void PrintSelf(ostream& os, vtkIndent indent) override;
58 
62  static vtkContext2D* New();
63 
69  bool Begin(vtkContextDevice2D* device);
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 
217  virtual void DrawMarkers(
218  int shape, bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
219  virtual void DrawMarkers(int shape, bool highlight, float* points, int n);
220  virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D* points);
221  virtual void DrawMarkers(
222  int shape, bool highlight, vtkPoints2D* points, vtkUnsignedCharArray* colors);
224 
228  void DrawRect(float x, float y, float w, float h);
229 
231 
234  void DrawQuad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);
235  void DrawQuad(float* p);
237 
239 
243  void DrawQuadStrip(float* p, int n);
245 
250  void DrawPolygon(float* x, float* y, int n);
251 
257 
263  void DrawPolygon(float* points, int n);
264 
269  void DrawPolygon(float* x, float* y, int n, unsigned char* color, int nc_comps);
270 
275  void DrawPolygon(vtkPoints2D* points, unsigned char* color, int nc_comps);
276 
282  void DrawPolygon(float* points, int n, unsigned char* color, int nc_comps);
283 
289  void DrawEllipse(float x, float y, float rx, float ry);
290 
299  void DrawWedge(
300  float x, float y, float outRadius, float inRadius, float startAngle, float stopAngle);
301 
313  void DrawEllipseWedge(float x, float y, float outRx, float outRy, float inRx, float inRy,
314  float startAngle, float stopAngle);
315 
321  void DrawArc(float x, float y, float r, float startAngle, float stopAngle);
322 
329  void DrawEllipticArc(float x, float y, float rX, float rY, float startAngle, float stopAngle);
330 
334  void DrawImage(float x, float y, vtkImageData* image);
335 
340  void DrawImage(float x, float y, float scale, vtkImageData* image);
341 
347  void DrawImage(const vtkRectf& pos, vtkImageData* image);
348 
354  float x, float y, vtkPolyData* polyData, vtkUnsignedCharArray* colors, int scalarMode);
355 
357 
362  void DrawStringRect(vtkPoints2D* rect, const vtkStdString& string);
363  VTK_DEPRECATED_IN_9_1_0("Use void DrawStringRect(vtkPoints2D* rect, const vtkStdString& string)")
364  void DrawStringRect(vtkPoints2D* rect, const vtkUnicodeString& string);
365  void DrawStringRect(vtkPoints2D* rect, const char* string);
366  void DrawStringRect(const float rect[4], const vtkStdString& string);
368  "Use void DrawStringRect(const float rect[4], const vtkStdString& string)")
369  void DrawStringRect(const float rect[4], const vtkUnicodeString& string);
370  void DrawStringRect(const float rect[4], const char* string);
372 
374 
377  void DrawString(vtkPoints2D* point, const vtkStdString& string);
378  void DrawString(float x, float y, const vtkStdString& string);
379  VTK_DEPRECATED_IN_9_1_0("Use void DrawString(vtkPoints2D* point, const vtkStdString& string)")
380  void DrawString(vtkPoints2D* point, const vtkUnicodeString& string);
381  VTK_DEPRECATED_IN_9_1_0("Use void DrawString(float x, float y, const vtkStdString& string)")
382  void DrawString(float x, float y, const vtkUnicodeString& string);
383  void DrawString(vtkPoints2D* point, const char* string);
384  void DrawString(float x, float y, const char* string);
386 
388 
397  void ComputeStringBounds(const vtkStdString& string, vtkPoints2D* bounds);
398  void ComputeStringBounds(const vtkStdString& string, float bounds[4]);
400  "Use void ComputeStringBounds(const vtkStdString& string, vtkPoints2D* bounds)")
401  void ComputeStringBounds(const vtkUnicodeString& string, vtkPoints2D* bounds);
403  "Use void ComputeStringBounds(const vtkStdString& string, float bounds[4])")
404  void ComputeStringBounds(const vtkUnicodeString& string, float bounds[4]);
405  void ComputeStringBounds(const char* string, vtkPoints2D* bounds);
406  void ComputeStringBounds(const char* string, float bounds[4]);
408 
413  void ComputeJustifiedStringBounds(const char* string, float bounds[4]);
414 
421  int ComputeFontSizeForBoundedString(const vtkStdString& string, float width, float height);
422 
424 
431  void DrawMathTextString(vtkPoints2D* point, const vtkStdString& string);
432  void DrawMathTextString(float x, float y, const vtkStdString& string);
433  void DrawMathTextString(vtkPoints2D* point, const char* string);
434  void DrawMathTextString(float x, float y, const char* string);
436 
438 
446  void DrawMathTextString(
447  vtkPoints2D* point, const vtkStdString& string, const vtkStdString& fallback);
448  void DrawMathTextString(
449  float x, float y, const vtkStdString& string, const vtkStdString& fallback);
450  void DrawMathTextString(vtkPoints2D* point, const char* string, const char* fallback);
451  void DrawMathTextString(float x, float y, const char* string, const char* fallback);
453 
457  bool MathTextIsSupported();
458 
464  void ApplyPen(vtkPen* pen);
465 
471  vtkPen* GetPen();
472 
478  void ApplyBrush(vtkBrush* brush);
479 
484  vtkBrush* GetBrush();
485 
491  void ApplyTextProp(vtkTextProperty* prop);
492 
496  vtkTextProperty* GetTextProp();
497 
503  void SetTransform(vtkTransform2D* transform);
504 
508  vtkTransform2D* GetTransform();
509 
516  void AppendTransform(vtkTransform2D* transform);
517 
519 
523  void PushMatrix();
524  void PopMatrix();
526 
530  void ApplyId(vtkIdType id);
531 
537  static int FloatToInt(float x);
538 
540 
544  vtkGetObjectMacro(Context3D, vtkContext3D);
545  virtual void SetContext3D(vtkContext3D* context);
547 
548 protected:
550  ~vtkContext2D() override;
551 
552  vtkContextDevice2D* Device; // The underlying device
553  vtkTransform2D* Transform; // Current transform
554 
556  vtkContext3D* Context3D; // May be very temporary - get at a 3D version.
557 
558 private:
559  vtkContext2D(const vtkContext2D&) = delete;
560  void operator=(const vtkContext2D&) = delete;
561 
568  vtkVector2f CalculateTextPosition(vtkPoints2D* rect);
569 
576  vtkVector2f CalculateTextPosition(const float rect[4]);
577 };
578 
579 inline int vtkContext2D::FloatToInt(float x)
580 {
581  // Use a tolerance of 1/256 of a pixel when converting.
582  // A float has only 24 bits of precision, so we cannot
583  // make the tolerance too small. For example, a tolerance
584  // of 2^-8 means that the tolerance will be significant
585  // for float values up to 2^16 or 65536.0. But a
586  // tolerance of 2^-16 would only be significant for
587  // float values up to 2^8 or 256.0. A small tolerance
588  // disappears into insignificance when added to a large float.
589  float tol = 0.00390625; // 1.0/256.0
590  tol = (x >= 0 ? tol : -tol);
591  return static_cast<int>(x + tol);
592 }
593 
594 #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::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:338
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)
vtkUnsignedCharArray
dynamic, self-adjusting array of unsigned char
Definition: vtkUnsignedCharArray.h:36
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:63
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:54
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:48
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:34
vtkUnicodeString
String class that stores Unicode text.
Definition: vtkUnicodeString.h:72
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)
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
vtkContextDevice2D
Abstract class for drawing 2D primitives.
Definition: vtkContextDevice2D.h:52
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.
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:86
vtkContext3D
Class for drawing 3D primitives to a graphical context.
Definition: vtkContext3D.h:41
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::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:336
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::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.