VTK  9.2.6
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 "vtkObject.h"
37 #include "vtkRenderingContext2DModule.h" // For export macro
38 
39 class vtkWindow;
40 
41 class vtkContext3D;
42 class vtkStdString;
43 class vtkTextProperty;
44 
45 class vtkPoints2D;
46 class vtkVector2f;
47 class vtkRectf;
49 class vtkContextDevice2D;
50 class vtkPen;
51 class vtkBrush;
52 class vtkImageData;
53 class vtkPolyData;
54 class vtkTransform2D;
56 
57 class VTKRENDERINGCONTEXT2D_EXPORT vtkContext2D : public vtkObject
58 {
59 public:
60  vtkTypeMacro(vtkContext2D, vtkObject);
61  void PrintSelf(ostream& os, vtkIndent indent) override;
62 
66  static vtkContext2D* New();
67 
73  bool Begin(vtkContextDevice2D* device);
74 
75  vtkGetObjectMacro(Device, vtkContextDevice2D);
76 
82  bool End();
83 
87  bool GetBufferIdMode() const;
88 
95  void BufferIdModeBegin(vtkAbstractContextBufferId* bufferId);
96 
103  void BufferIdModeEnd();
104 
108  void DrawLine(float x1, float y1, float x2, float y2);
109 
113  void DrawLine(float p[4]);
114 
119  void DrawLine(vtkPoints2D* points);
120 
124  void DrawPoly(float* x, float* y, int n);
125 
130  void DrawPoly(vtkPoints2D* points);
131 
137  void DrawPoly(float* points, int n);
138 
145  void DrawPoly(float* points, int n, unsigned char* colors, int nc_comps);
146 
151  void DrawLines(vtkPoints2D* points);
152 
157  void DrawLines(float* points, int n);
158 
162  void DrawPoint(float x, float y);
163 
167  void DrawPoints(float* x, float* y, int n);
168 
173  void DrawPoints(vtkPoints2D* points);
174 
180  void DrawPoints(float* points, int n);
181 
187  void DrawPointSprites(vtkImageData* sprite, vtkPoints2D* points);
188 
190 
196  void DrawPointSprites(vtkImageData* sprite, vtkPoints2D* points, vtkUnsignedCharArray* colors);
197  void DrawPointSprites(
198  vtkImageData* sprite, float* points, int n, unsigned char* colors, int nc_comps);
200 
206  void DrawPointSprites(vtkImageData* sprite, float* points, int n);
207 
209 
225  virtual void DrawMarkers(
226  int shape, bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
227  virtual void DrawMarkers(int shape, bool highlight, float* points, int n);
228  virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D* points);
229  virtual void DrawMarkers(
230  int shape, bool highlight, vtkPoints2D* points, vtkUnsignedCharArray* colors);
232 
236  void DrawRect(float x, float y, float w, float h);
237 
239 
242  void DrawQuad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);
243  void DrawQuad(float* p);
245 
247 
250  void DrawQuadStrip(vtkPoints2D* points);
251  void DrawQuadStrip(float* p, int n);
253 
258  void DrawPolygon(float* x, float* y, int n);
259 
264  void DrawPolygon(vtkPoints2D* points);
265 
271  void DrawPolygon(float* points, int n);
272 
277  void DrawPolygon(float* x, float* y, int n, unsigned char* color, int nc_comps);
278 
283  void DrawPolygon(vtkPoints2D* points, unsigned char* color, int nc_comps);
284 
290  void DrawPolygon(float* points, int n, unsigned char* color, int nc_comps);
291 
297  void DrawEllipse(float x, float y, float rx, float ry);
298 
307  void DrawWedge(
308  float x, float y, float outRadius, float inRadius, float startAngle, float stopAngle);
309 
321  void DrawEllipseWedge(float x, float y, float outRx, float outRy, float inRx, float inRy,
322  float startAngle, float stopAngle);
323 
329  void DrawArc(float x, float y, float r, float startAngle, float stopAngle);
330 
337  void DrawEllipticArc(float x, float y, float rX, float rY, float startAngle, float stopAngle);
338 
342  void DrawImage(float x, float y, vtkImageData* image);
343 
348  void DrawImage(float x, float y, float scale, vtkImageData* image);
349 
355  void DrawImage(const vtkRectf& pos, vtkImageData* image);
356 
361  void DrawPolyData(
362  float x, float y, vtkPolyData* polyData, vtkUnsignedCharArray* colors, int scalarMode);
363 
365 
370  void DrawStringRect(vtkPoints2D* rect, const vtkStdString& string);
371  void DrawStringRect(vtkPoints2D* rect, const char* string);
372  void DrawStringRect(const float rect[4], const vtkStdString& string);
373  void DrawStringRect(const float rect[4], const char* string);
375 
377 
380  void DrawString(vtkPoints2D* point, const vtkStdString& string);
381  void DrawString(float x, float y, const vtkStdString& string);
382  void DrawString(vtkPoints2D* point, const char* string);
383  void DrawString(float x, float y, const char* string);
385 
387 
396  void ComputeStringBounds(const vtkStdString& string, vtkPoints2D* bounds);
397  void ComputeStringBounds(const vtkStdString& string, float bounds[4]);
398  void ComputeStringBounds(const char* string, vtkPoints2D* bounds);
399  void ComputeStringBounds(const char* string, float bounds[4]);
401 
406  void ComputeJustifiedStringBounds(const char* string, float bounds[4]);
407 
414  int ComputeFontSizeForBoundedString(const vtkStdString& string, float width, float height);
415 
417 
424  void DrawMathTextString(vtkPoints2D* point, const vtkStdString& string);
425  void DrawMathTextString(float x, float y, const vtkStdString& string);
426  void DrawMathTextString(vtkPoints2D* point, const char* string);
427  void DrawMathTextString(float x, float y, const char* string);
429 
431 
439  void DrawMathTextString(
440  vtkPoints2D* point, const vtkStdString& string, const vtkStdString& fallback);
441  void DrawMathTextString(
442  float x, float y, const vtkStdString& string, const vtkStdString& fallback);
443  void DrawMathTextString(vtkPoints2D* point, const char* string, const char* fallback);
444  void DrawMathTextString(float x, float y, const char* string, const char* fallback);
446 
450  bool MathTextIsSupported();
451 
457  void ApplyPen(vtkPen* pen);
458 
464  vtkPen* GetPen();
465 
471  void ApplyBrush(vtkBrush* brush);
472 
477  vtkBrush* GetBrush();
478 
484  void ApplyTextProp(vtkTextProperty* prop);
485 
489  vtkTextProperty* GetTextProp();
490 
496  void SetTransform(vtkTransform2D* transform);
497 
501  vtkTransform2D* GetTransform();
502 
509  void AppendTransform(vtkTransform2D* transform);
510 
512 
516  void PushMatrix();
517  void PopMatrix();
519 
523  void ApplyId(vtkIdType id);
524 
530  static int FloatToInt(float x);
531 
533 
537  vtkGetObjectMacro(Context3D, vtkContext3D);
538  virtual void SetContext3D(vtkContext3D* context);
540 
541 protected:
542  vtkContext2D();
543  ~vtkContext2D() override;
544 
545  vtkContextDevice2D* Device; // The underlying device
546  vtkTransform2D* Transform; // Current transform
547 
549  vtkContext3D* Context3D; // May be very temporary - get at a 3D version.
550 
551 private:
552  vtkContext2D(const vtkContext2D&) = delete;
553  void operator=(const vtkContext2D&) = delete;
554 
561  vtkVector2f CalculateTextPosition(vtkPoints2D* rect);
562 
569  vtkVector2f CalculateTextPosition(const float rect[4]);
570 };
571 
572 inline int vtkContext2D::FloatToInt(float x)
573 {
574  // Use a tolerance of 1/256 of a pixel when converting.
575  // A float has only 24 bits of precision, so we cannot
576  // make the tolerance too small. For example, a tolerance
577  // of 2^-8 means that the tolerance will be significant
578  // for float values up to 2^16 or 65536.0. But a
579  // tolerance of 2^-16 would only be significant for
580  // float values up to 2^8 or 256.0. A small tolerance
581  // disappears into insignificance when added to a large float.
582  float tol = 0.00390625; // 1.0/256.0
583  tol = (x >= 0 ? tol : -tol);
584  return static_cast<int>(x + tol);
585 }
586 
587 #endif // vtkContext2D_h
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:38
vtkAbstractContextBufferId * BufferId
Definition: vtkContext2D.h:548
abstract base class for most VTK objects
Definition: vtkObject.h:62
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int vtkIdType
Definition: vtkType.h:332
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:90
static int FloatToInt(float x)
Float to int conversion, performs truncation but with a rounding tolerance for float values that are ...
Definition: vtkContext2D.h:572
window superclass for vtkRenderWindow
Definition: vtkWindow.h:38
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:57
provides a brush that fills shapes drawn by vtkContext2D.
Definition: vtkBrush.h:40
a simple class to control print indentation
Definition: vtkIndent.h:39
represent and manipulate 2D points
Definition: vtkPoints2D.h:36
topologically and geometrically regular array of data
Definition: vtkImageData.h:53
Abstract class for drawing 2D primitives.
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:39
describes linear transformations via a 3x3 matrix
represent text properties.
vtkContextDevice2D * Device
Definition: vtkContext2D.h:545
dynamic, self-adjusting array of unsigned char
2D array of ids, used for picking.
vtkTransform2D * Transform
Definition: vtkContext2D.h:546
vtkContext3D * Context3D
Definition: vtkContext2D.h:549
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
Class for drawing 3D primitives to a graphical context.
Definition: vtkContext3D.h:40