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 
27 #ifndef vtkContext2D_h
28 #define vtkContext2D_h
29 
30 #include "vtkRenderingContext2DModule.h" // For export macro
31 #include "vtkObject.h"
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,
141  unsigned char *colors, int nc_comps);
142 
147  void DrawLines(vtkPoints2D *points);
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 
169  void DrawPoints(vtkPoints2D *points);
170 
176  void DrawPoints(float *points, int n);
177 
183  void DrawPointSprites(vtkImageData *sprite, vtkPoints2D *points);
184 
186 
192  void DrawPointSprites(vtkImageData *sprite, vtkPoints2D *points,
193  vtkUnsignedCharArray *colors);
194  void DrawPointSprites(vtkImageData *sprite, float *points, int n,
195  unsigned char *colors, int nc_comps);
197 
203  void DrawPointSprites(vtkImageData *sprite, float *points, int n);
204 
206 
218  virtual void DrawMarkers(int shape, bool highlight, float *points, int n,
219  unsigned char *colors, int nc_comps);
220  virtual void DrawMarkers(int shape, bool highlight, float *points, int n);
221  virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D *points);
222  virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D *points,
223  vtkUnsignedCharArray *colors);
225 
229  void DrawRect(float x, float y, float w, float h);
230 
232 
235  void DrawQuad(float x1, float y1, float x2, float y2,
236  float x3, float y3, float x4, float y4);
237  void DrawQuad(float *p);
239 
241 
244  void DrawQuadStrip(vtkPoints2D *points);
245  void DrawQuadStrip(float *p, int n);
247 
252  void DrawPolygon(float *x, float *y, int n);
253 
258  void DrawPolygon(vtkPoints2D *points);
259 
265  void DrawPolygon(float *points, int n);
266 
271  void DrawPolygon(float *x, float *y, int n,
272  unsigned char *color, int nc_comps);
273 
278  void DrawPolygon(vtkPoints2D *points,
279  unsigned char *color, int nc_comps);
280 
286  void DrawPolygon(float *points, int n,
287  unsigned char *color, int nc_comps);
288 
294  void DrawEllipse(float x, float y, float rx, float ry);
295 
304  void DrawWedge(float x, float y, float outRadius,
305  float inRadius,float startAngle,
306  float stopAngle);
307 
319  void DrawEllipseWedge(float x, float y, float outRx, float outRy,
320  float inRx, float inRy, float startAngle,
321  float stopAngle);
322 
323 
329  void DrawArc(float x, float y, float r, float startAngle,
330  float stopAngle);
331 
338  void DrawEllipticArc(float x, float y, float rX, float rY, float startAngle,
339  float stopAngle);
340 
341 
345  void DrawImage(float x, float y, vtkImageData *image);
346 
351  void DrawImage(float x, float y, float scale, vtkImageData *image);
352 
358  void DrawImage(const vtkRectf& pos, vtkImageData *image);
359 
364  void DrawPolyData(float x, float y, vtkPolyData* polyData,
365  vtkUnsignedCharArray* colors, int scalarMode);
366 
368 
373  void DrawStringRect(vtkPoints2D *rect, const vtkStdString &string);
374  void DrawStringRect(vtkPoints2D *rect, const vtkUnicodeString &string);
375  void DrawStringRect(vtkPoints2D *rect, const char* string);
377 
379 
382  void DrawString(vtkPoints2D *point, const vtkStdString &string);
383  void DrawString(float x, float y, const vtkStdString &string);
384  void DrawString(vtkPoints2D *point, const vtkUnicodeString &string);
385  void DrawString(float x, float y, const vtkUnicodeString &string);
386  void DrawString(vtkPoints2D *point, const char* string);
387  void DrawString(float x, float y, const char* string);
389 
391 
400  void ComputeStringBounds(const vtkStdString &string, vtkPoints2D *bounds);
401  void ComputeStringBounds(const vtkStdString &string, float bounds[4]);
402  void ComputeStringBounds(const vtkUnicodeString &string, vtkPoints2D *bounds);
403  void ComputeStringBounds(const vtkUnicodeString &string, float bounds[4]);
404  void ComputeStringBounds(const char* string, vtkPoints2D *bounds);
405  void ComputeStringBounds(const char* string, float bounds[4]);
407 
412  void ComputeJustifiedStringBounds(const char* string, float bounds[4]);
413 
420  int ComputeFontSizeForBoundedString(const vtkStdString &string, float width,
421  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(vtkPoints2D *point, const vtkStdString &string,
447  const vtkStdString &fallback);
448  void DrawMathTextString(float x, float y, const vtkStdString &string,
449  const vtkStdString &fallback);
450  void DrawMathTextString(vtkPoints2D *point, const char *string,
451  const char *fallback);
452  void DrawMathTextString(float x, float y, const char *string,
453  const char *fallback);
455 
456 
460  bool MathTextIsSupported();
461 
467  void ApplyPen(vtkPen *pen);
468 
474  vtkPen* GetPen();
475 
481  void ApplyBrush(vtkBrush *brush);
482 
487  vtkBrush* GetBrush();
488 
494  void ApplyTextProp(vtkTextProperty *prop);
495 
499  vtkTextProperty* GetTextProp();
500 
506  void SetTransform(vtkTransform2D *transform);
507 
511  vtkTransform2D* GetTransform();
512 
519  void AppendTransform(vtkTransform2D *transform);
520 
522 
526  void PushMatrix();
527  void PopMatrix();
529 
533  void ApplyId(vtkIdType id);
534 
540  static int FloatToInt(float x);
541 
543 
547  vtkGetObjectMacro(Context3D, vtkContext3D)
548  virtual void SetContext3D(vtkContext3D *context);
550 
551 protected:
552  vtkContext2D();
553  ~vtkContext2D() override;
554 
555  vtkContextDevice2D *Device; // The underlying device
556  vtkTransform2D *Transform; // Current transform
557 
559  vtkContext3D *Context3D; // May be very temporary - get at a 3D version.
560 
561 private:
562  vtkContext2D(const vtkContext2D &) = delete;
563  void operator=(const vtkContext2D &) = delete;
564 
571  vtkVector2f CalculateTextPosition(vtkPoints2D* rect);
572 
579  vtkVector2f CalculateTextPosition(float rect[4]);
580 
581 };
582 
583 inline int vtkContext2D::FloatToInt(float x)
584 {
585  // Use a tolerance of 1/256 of a pixel when converting.
586  // A float has only 24 bits of precision, so we cannot
587  // make the tolerance too small. For example, a tolerance
588  // of 2^-8 means that the tolerance will be significant
589  // for float values up to 2^16 or 65536.0. But a
590  // tolerance of 2^-16 would only be significant for
591  // float values up to 2^8 or 256.0. A small tolerance
592  // disappears into insignificance when added to a large float.
593  float tol = 0.00390625; // 1.0/256.0
594  tol = (x >= 0 ? tol : -tol);
595  return static_cast<int>(x + tol);
596 }
597 
598 #endif //vtkContext2D_h
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:34
vtkAbstractContextBufferId * BufferId
Definition: vtkContext2D.h:558
abstract base class for most VTK objects
Definition: vtkObject.h:53
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int vtkIdType
Definition: vtkType.h:345
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:79
static int FloatToInt(float x)
Float to int conversion, performs truncation but with a rounding tolerance for float values that are ...
Definition: vtkContext2D.h:583
window superclass for vtkRenderWindow
Definition: vtkWindow.h:34
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:52
provides a brush that fills shapes drawn by vtkContext2D.
Definition: vtkBrush.h:37
a simple class to control print indentation
Definition: vtkIndent.h:33
represent and manipulate 2D points
Definition: vtkPoints2D.h:33
topologically and geometrically regular array of data
Definition: vtkImageData.h:39
Abstract class for drawing 2D primitives.
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:36
describes linear transformations via a 3x3 matrix
represent text properties.
vtkContextDevice2D * Device
Definition: vtkContext2D.h:555
dynamic, self-adjusting array of unsigned char
2D array of ids, used for picking.
vtkTransform2D * Transform
Definition: vtkContext2D.h:556
vtkContext3D * Context3D
Definition: vtkContext2D.h:559
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
String class that stores Unicode text.
Class for drawing 3D primitives to a graphical context.
Definition: vtkContext3D.h:40