VTK  9.0.20200711
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 
90  void BufferIdModeBegin(vtkAbstractContextBufferId* bufferId);
91 
98  void BufferIdModeEnd();
99 
103  void DrawLine(float x1, float y1, float x2, float y2);
104 
108  void DrawLine(float p[4]);
109 
114  void DrawLine(vtkPoints2D* points);
115 
119  void DrawPoly(float* x, float* y, int n);
120 
125  void DrawPoly(vtkPoints2D* points);
126 
132  void DrawPoly(float* points, int n);
133 
140  void DrawPoly(float* points, int n, unsigned char* colors, int nc_comps);
141 
146  void DrawLines(vtkPoints2D* points);
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 
168  void DrawPoints(vtkPoints2D* points);
169 
175  void DrawPoints(float* points, int n);
176 
182  void DrawPointSprites(vtkImageData* sprite, vtkPoints2D* points);
183 
185 
191  void DrawPointSprites(vtkImageData* sprite, vtkPoints2D* points, vtkUnsignedCharArray* colors);
192  void DrawPointSprites(
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 
241  void DrawQuadStrip(vtkPoints2D* points);
242  void DrawQuadStrip(float* p, int n);
244 
249  void DrawPolygon(float* x, float* y, int n);
250 
255  void DrawPolygon(vtkPoints2D* points);
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 
352  void DrawPolyData(
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);
364  void DrawStringRect(const float rect[4], const vtkStdString& string);
365  void DrawStringRect(const float rect[4], const vtkUnicodeString& string);
366  void DrawStringRect(const float rect[4], const char* string);
368 
370 
373  void DrawString(vtkPoints2D* point, const vtkStdString& string);
374  void DrawString(float x, float y, const vtkStdString& string);
375  void DrawString(vtkPoints2D* point, const vtkUnicodeString& string);
376  void DrawString(float x, float y, const vtkUnicodeString& string);
377  void DrawString(vtkPoints2D* point, const char* string);
378  void DrawString(float x, float y, const char* string);
380 
382 
391  void ComputeStringBounds(const vtkStdString& string, vtkPoints2D* bounds);
392  void ComputeStringBounds(const vtkStdString& string, float bounds[4]);
393  void ComputeStringBounds(const vtkUnicodeString& string, vtkPoints2D* bounds);
394  void ComputeStringBounds(const vtkUnicodeString& string, float bounds[4]);
395  void ComputeStringBounds(const char* string, vtkPoints2D* bounds);
396  void ComputeStringBounds(const char* string, float bounds[4]);
398 
403  void ComputeJustifiedStringBounds(const char* string, float bounds[4]);
404 
411  int ComputeFontSizeForBoundedString(const vtkStdString& string, float width, float height);
412 
414 
421  void DrawMathTextString(vtkPoints2D* point, const vtkStdString& string);
422  void DrawMathTextString(float x, float y, const vtkStdString& string);
423  void DrawMathTextString(vtkPoints2D* point, const char* string);
424  void DrawMathTextString(float x, float y, const char* string);
426 
428 
436  void DrawMathTextString(
437  vtkPoints2D* point, const vtkStdString& string, const vtkStdString& fallback);
438  void DrawMathTextString(
439  float x, float y, const vtkStdString& string, const vtkStdString& fallback);
440  void DrawMathTextString(vtkPoints2D* point, const char* string, const char* fallback);
441  void DrawMathTextString(float x, float y, const char* string, const char* fallback);
443 
447  bool MathTextIsSupported();
448 
454  void ApplyPen(vtkPen* pen);
455 
461  vtkPen* GetPen();
462 
468  void ApplyBrush(vtkBrush* brush);
469 
474  vtkBrush* GetBrush();
475 
481  void ApplyTextProp(vtkTextProperty* prop);
482 
486  vtkTextProperty* GetTextProp();
487 
493  void SetTransform(vtkTransform2D* transform);
494 
498  vtkTransform2D* GetTransform();
499 
506  void AppendTransform(vtkTransform2D* transform);
507 
509 
513  void PushMatrix();
514  void PopMatrix();
516 
520  void ApplyId(vtkIdType id);
521 
527  static int FloatToInt(float x);
528 
530 
534  vtkGetObjectMacro(Context3D, vtkContext3D);
535  virtual void SetContext3D(vtkContext3D* context);
537 
538 protected:
539  vtkContext2D();
540  ~vtkContext2D() override;
541 
542  vtkContextDevice2D* Device; // The underlying device
543  vtkTransform2D* Transform; // Current transform
544 
546  vtkContext3D* Context3D; // May be very temporary - get at a 3D version.
547 
548 private:
549  vtkContext2D(const vtkContext2D&) = delete;
550  void operator=(const vtkContext2D&) = delete;
551 
558  vtkVector2f CalculateTextPosition(vtkPoints2D* rect);
559 
566  vtkVector2f CalculateTextPosition(const float rect[4]);
567 };
568 
569 inline int vtkContext2D::FloatToInt(float x)
570 {
571  // Use a tolerance of 1/256 of a pixel when converting.
572  // A float has only 24 bits of precision, so we cannot
573  // make the tolerance too small. For example, a tolerance
574  // of 2^-8 means that the tolerance will be significant
575  // for float values up to 2^16 or 65536.0. But a
576  // tolerance of 2^-16 would only be significant for
577  // float values up to 2^8 or 256.0. A small tolerance
578  // disappears into insignificance when added to a large float.
579  float tol = 0.00390625; // 1.0/256.0
580  tol = (x >= 0 ? tol : -tol);
581  return static_cast<int>(x + tol);
582 }
583 
584 #endif // vtkContext2D_h
vtkBrush
provides a brush that fills shapes drawn by vtkContext2D.
Definition: vtkBrush.h:37
vtkPoints2D
represent and manipulate 2D points
Definition: vtkPoints2D.h:33
vtkX3D::scale
Definition: vtkX3D.h:235
vtkIdType
int vtkIdType
Definition: vtkType.h:330
vtkTransform2D
describes linear transformations via a 3x3 matrix
Definition: vtkTransform2D.h:45
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkX3D::image
Definition: vtkX3D.h:380
vtkUnsignedCharArray
dynamic, self-adjusting array of unsigned char
Definition: vtkUnsignedCharArray.h:35
vtkContext2D::BufferId
vtkAbstractContextBufferId * BufferId
Definition: vtkContext2D.h:545
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:62
vtkContext2D
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:52
vtkWindow
window superclass for vtkRenderWindow
Definition: vtkWindow.h:38
vtkContext2D::Transform
vtkTransform2D * Transform
Definition: vtkContext2D.h:543
vtkAbstractContextBufferId
2D array of ids, used for picking.
Definition: vtkAbstractContextBufferId.h:46
vtkContext2D::Context3D
vtkContext3D * Context3D
Definition: vtkContext2D.h:546
vtkX3D::color
Definition: vtkX3D.h:227
vtkX3D::points
Definition: vtkX3D.h:452
vtkX3D::point
Definition: vtkX3D.h:242
vtkContext2D::Device
vtkContextDevice2D * Device
Definition: vtkContext2D.h:542
vtkX3D::height
Definition: vtkX3D.h:260
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:569
vtkImageData
topologically and geometrically regular array of data
Definition: vtkImageData.h:41
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkUnicodeString
String class that stores Unicode text.
Definition: vtkUnicodeString.h:69
vtkObject::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkX3D::startAngle
Definition: vtkX3D.h:492
vtkObject.h
vtkContextDevice2D
Abstract class for drawing 2D primitives.
Definition: vtkContextDevice2D.h:50
vtkTextProperty
represent text properties.
Definition: vtkTextProperty.h:33
vtkPolyData
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:85
vtkContext3D
Class for drawing 3D primitives to a graphical context.
Definition: vtkContext3D.h:40
vtkPen
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:36
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:34
vtkRectf
Definition: vtkRect.h:326
vtkVector2f
Definition: vtkVector.h:432
h