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 
33 #ifndef vtkContext2D_h
34 #define vtkContext2D_h
35 
36 #include "vtkRenderingContext2DModule.h" // For export macro
37 #include "vtkObject.h"
38 
39 class vtkWindow;
40 
41 class vtkContext3D;
42 class vtkStdString;
43 class vtkUnicodeString;
44 class vtkTextProperty;
45 
46 class vtkPoints2D;
47 class vtkVector2f;
48 class vtkRectf;
50 class vtkContextDevice2D;
51 class vtkPen;
52 class vtkBrush;
53 class vtkImageData;
54 class vtkPolyData;
55 class vtkTransform2D;
57 
58 class VTKRENDERINGCONTEXT2D_EXPORT vtkContext2D : public vtkObject
59 {
60 public:
61  vtkTypeMacro(vtkContext2D, vtkObject);
62  void PrintSelf(ostream &os, vtkIndent indent) override;
63 
67  static vtkContext2D *New();
68 
74  bool Begin(vtkContextDevice2D *device);
75 
76  vtkGetObjectMacro(Device, vtkContextDevice2D);
77 
83  bool End();
84 
88  bool GetBufferIdMode() const;
89 
96  void BufferIdModeBegin(vtkAbstractContextBufferId *bufferId);
97 
104  void BufferIdModeEnd();
105 
109  void DrawLine(float x1, float y1, float x2, float y2);
110 
114  void DrawLine(float p[4]);
115 
120  void DrawLine(vtkPoints2D *points);
121 
125  void DrawPoly(float *x, float *y, int n);
126 
131  void DrawPoly(vtkPoints2D *points);
132 
138  void DrawPoly(float *points, int n);
139 
146  void DrawPoly(float *points, int n,
147  unsigned char *colors, int nc_comps);
148 
153  void DrawLines(vtkPoints2D *points);
154 
159  void DrawLines(float *points, int n);
160 
164  void DrawPoint(float x, float y);
165 
169  void DrawPoints(float *x, float *y, int n);
170 
175  void DrawPoints(vtkPoints2D *points);
176 
182  void DrawPoints(float *points, int n);
183 
189  void DrawPointSprites(vtkImageData *sprite, vtkPoints2D *points);
190 
192 
198  void DrawPointSprites(vtkImageData *sprite, vtkPoints2D *points,
199  vtkUnsignedCharArray *colors);
200  void DrawPointSprites(vtkImageData *sprite, float *points, int n,
201  unsigned char *colors, int nc_comps);
203 
209  void DrawPointSprites(vtkImageData *sprite, float *points, int n);
210 
212 
224  virtual void DrawMarkers(int shape, bool highlight, float *points, int n,
225  unsigned char *colors, int nc_comps);
226  virtual void DrawMarkers(int shape, bool highlight, float *points, int n);
227  virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D *points);
228  virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D *points,
229  vtkUnsignedCharArray *colors);
231 
235  void DrawRect(float x, float y, float w, float h);
236 
238 
241  void DrawQuad(float x1, float y1, float x2, float y2,
242  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,
278  unsigned char *color, int nc_comps);
279 
284  void DrawPolygon(vtkPoints2D *points,
285  unsigned char *color, int nc_comps);
286 
292  void DrawPolygon(float *points, int n,
293  unsigned char *color, int nc_comps);
294 
300  void DrawEllipse(float x, float y, float rx, float ry);
301 
310  void DrawWedge(float x, float y, float outRadius,
311  float inRadius,float startAngle,
312  float stopAngle);
313 
325  void DrawEllipseWedge(float x, float y, float outRx, float outRy,
326  float inRx, float inRy, float startAngle,
327  float stopAngle);
328 
329 
335  void DrawArc(float x, float y, float r, float startAngle,
336  float stopAngle);
337 
344  void DrawEllipticArc(float x, float y, float rX, float rY, float startAngle,
345  float stopAngle);
346 
347 
351  void DrawImage(float x, float y, vtkImageData *image);
352 
357  void DrawImage(float x, float y, float scale, vtkImageData *image);
358 
364  void DrawImage(const vtkRectf& pos, vtkImageData *image);
365 
370  void DrawPolyData(float x, float y, vtkPolyData* polyData,
371  vtkUnsignedCharArray* colors, int scalarMode);
372 
374 
379  void DrawStringRect(vtkPoints2D *rect, const vtkStdString &string);
380  void DrawStringRect(vtkPoints2D *rect, const vtkUnicodeString &string);
381  void DrawStringRect(vtkPoints2D *rect, const char* string);
383 
385 
388  void DrawString(vtkPoints2D *point, const vtkStdString &string);
389  void DrawString(float x, float y, const vtkStdString &string);
390  void DrawString(vtkPoints2D *point, const vtkUnicodeString &string);
391  void DrawString(float x, float y, const vtkUnicodeString &string);
392  void DrawString(vtkPoints2D *point, const char* string);
393  void DrawString(float x, float y, const char* string);
395 
397 
406  void ComputeStringBounds(const vtkStdString &string, vtkPoints2D *bounds);
407  void ComputeStringBounds(const vtkStdString &string, float bounds[4]);
408  void ComputeStringBounds(const vtkUnicodeString &string, vtkPoints2D *bounds);
409  void ComputeStringBounds(const vtkUnicodeString &string, float bounds[4]);
410  void ComputeStringBounds(const char* string, vtkPoints2D *bounds);
411  void ComputeStringBounds(const char* string, float bounds[4]);
413 
418  void ComputeJustifiedStringBounds(const char* string, float bounds[4]);
419 
426  int ComputeFontSizeForBoundedString(const vtkStdString &string, float width,
427  float height);
428 
430 
437  void DrawMathTextString(vtkPoints2D *point, const vtkStdString &string);
438  void DrawMathTextString(float x, float y, const vtkStdString &string);
439  void DrawMathTextString(vtkPoints2D *point, const char *string);
440  void DrawMathTextString(float x, float y, const char *string);
442 
444 
452  void DrawMathTextString(vtkPoints2D *point, const vtkStdString &string,
453  const vtkStdString &fallback);
454  void DrawMathTextString(float x, float y, const vtkStdString &string,
455  const vtkStdString &fallback);
456  void DrawMathTextString(vtkPoints2D *point, const char *string,
457  const char *fallback);
458  void DrawMathTextString(float x, float y, const char *string,
459  const char *fallback);
461 
462 
466  bool MathTextIsSupported();
467 
473  void ApplyPen(vtkPen *pen);
474 
480  vtkPen* GetPen();
481 
487  void ApplyBrush(vtkBrush *brush);
488 
493  vtkBrush* GetBrush();
494 
500  void ApplyTextProp(vtkTextProperty *prop);
501 
505  vtkTextProperty* GetTextProp();
506 
512  void SetTransform(vtkTransform2D *transform);
513 
517  vtkTransform2D* GetTransform();
518 
525  void AppendTransform(vtkTransform2D *transform);
526 
528 
532  void PushMatrix();
533  void PopMatrix();
535 
539  void ApplyId(vtkIdType id);
540 
546  static int FloatToInt(float x);
547 
549 
553  vtkGetObjectMacro(Context3D, vtkContext3D)
554  virtual void SetContext3D(vtkContext3D *context);
556 
557 protected:
558  vtkContext2D();
559  ~vtkContext2D() override;
560 
561  vtkContextDevice2D *Device; // The underlying device
562  vtkTransform2D *Transform; // Current transform
563 
565  vtkContext3D *Context3D; // May be very temporary - get at a 3D version.
566 
567 private:
568  vtkContext2D(const vtkContext2D &) = delete;
569  void operator=(const vtkContext2D &) = delete;
570 
577  vtkVector2f CalculateTextPosition(vtkPoints2D* rect);
578 
585  vtkVector2f CalculateTextPosition(float rect[4]);
586 
587 };
588 
589 inline int vtkContext2D::FloatToInt(float x)
590 {
591  // Use a tolerance of 1/256 of a pixel when converting.
592  // A float has only 24 bits of precision, so we cannot
593  // make the tolerance too small. For example, a tolerance
594  // of 2^-8 means that the tolerance will be significant
595  // for float values up to 2^16 or 65536.0. But a
596  // tolerance of 2^-16 would only be significant for
597  // float values up to 2^8 or 256.0. A small tolerance
598  // disappears into insignificance when added to a large float.
599  float tol = 0.00390625; // 1.0/256.0
600  tol = (x >= 0 ? tol : -tol);
601  return static_cast<int>(x + tol);
602 }
603 
604 #endif //vtkContext2D_h
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:40
abstract base class for most VTK objects
Definition: vtkObject.h:59
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int vtkIdType
Definition: vtkType.h:347
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:85
window superclass for vtkRenderWindow
Definition: vtkWindow.h:37
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:58
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:45
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.
dynamic, self-adjusting array of unsigned char
2D array of ids, used for picking.
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.
Transform
Definition: ADIOSDefs.h:40
Class for drawing 3D primitives to a graphical context.
Definition: vtkContext3D.h:40