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) VTK_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 
278  void DrawEllipse(float x, float y, float rx, float ry);
279 
288  void DrawWedge(float x, float y, float outRadius,
289  float inRadius,float startAngle,
290  float stopAngle);
291 
303  void DrawEllipseWedge(float x, float y, float outRx, float outRy,
304  float inRx, float inRy, float startAngle,
305  float stopAngle);
306 
307 
313  void DrawArc(float x, float y, float r, float startAngle,
314  float stopAngle);
315 
322  void DrawEllipticArc(float x, float y, float rX, float rY, float startAngle,
323  float stopAngle);
324 
325 
329  void DrawImage(float x, float y, vtkImageData *image);
330 
335  void DrawImage(float x, float y, float scale, vtkImageData *image);
336 
342  void DrawImage(const vtkRectf& pos, vtkImageData *image);
343 
348  void DrawPolyData(float x, float y, vtkPolyData* polyData,
349  vtkUnsignedCharArray* colors, int scalarMode);
350 
352 
357  void DrawStringRect(vtkPoints2D *rect, const vtkStdString &string);
358  void DrawStringRect(vtkPoints2D *rect, const vtkUnicodeString &string);
359  void DrawStringRect(vtkPoints2D *rect, const char* string);
361 
363 
366  void DrawString(vtkPoints2D *point, const vtkStdString &string);
367  void DrawString(float x, float y, const vtkStdString &string);
368  void DrawString(vtkPoints2D *point, const vtkUnicodeString &string);
369  void DrawString(float x, float y, const vtkUnicodeString &string);
370  void DrawString(vtkPoints2D *point, const char* string);
371  void DrawString(float x, float y, const char* string);
373 
375 
384  void ComputeStringBounds(const vtkStdString &string, vtkPoints2D *bounds);
385  void ComputeStringBounds(const vtkStdString &string, float bounds[4]);
386  void ComputeStringBounds(const vtkUnicodeString &string, vtkPoints2D *bounds);
387  void ComputeStringBounds(const vtkUnicodeString &string, float bounds[4]);
388  void ComputeStringBounds(const char* string, vtkPoints2D *bounds);
389  void ComputeStringBounds(const char* string, float bounds[4]);
391 
396  void ComputeJustifiedStringBounds(const char* string, float bounds[4]);
397 
404  int ComputeFontSizeForBoundedString(const vtkStdString &string, float width,
405  float height);
406 
408 
415  void DrawMathTextString(vtkPoints2D *point, const vtkStdString &string);
416  void DrawMathTextString(float x, float y, const vtkStdString &string);
417  void DrawMathTextString(vtkPoints2D *point, const char *string);
418  void DrawMathTextString(float x, float y, const char *string);
420 
422 
430  void DrawMathTextString(vtkPoints2D *point, const vtkStdString &string,
431  const vtkStdString &fallback);
432  void DrawMathTextString(float x, float y, const vtkStdString &string,
433  const vtkStdString &fallback);
434  void DrawMathTextString(vtkPoints2D *point, const char *string,
435  const char *fallback);
436  void DrawMathTextString(float x, float y, const char *string,
437  const char *fallback);
439 
440 
444  bool MathTextIsSupported();
445 
451  void ApplyPen(vtkPen *pen);
452 
458  vtkPen* GetPen();
459 
465  void ApplyBrush(vtkBrush *brush);
466 
471  vtkBrush* GetBrush();
472 
478  void ApplyTextProp(vtkTextProperty *prop);
479 
483  vtkTextProperty* GetTextProp();
484 
490  void SetTransform(vtkTransform2D *transform);
491 
495  vtkTransform2D* GetTransform();
496 
503  void AppendTransform(vtkTransform2D *transform);
504 
506 
510  void PushMatrix();
511  void PopMatrix();
513 
517  void ApplyId(vtkIdType id);
518 
524  static int FloatToInt(float x);
525 
527 
531  vtkGetObjectMacro(Context3D, vtkContext3D)
532  virtual void SetContext3D(vtkContext3D *context);
534 
535 protected:
536  vtkContext2D();
537  ~vtkContext2D() VTK_OVERRIDE;
538 
539  vtkContextDevice2D *Device; // The underlying device
540  vtkTransform2D *Transform; // Current transform
541 
543  vtkContext3D *Context3D; // May be very temporary - get at a 3D version.
544 
545 private:
546  vtkContext2D(const vtkContext2D &) VTK_DELETE_FUNCTION;
547  void operator=(const vtkContext2D &) VTK_DELETE_FUNCTION;
548 
555  vtkVector2f CalculateTextPosition(vtkPoints2D* rect);
556 
563  vtkVector2f CalculateTextPosition(float rect[4]);
564 
565 };
566 
567 inline int vtkContext2D::FloatToInt(float x)
568 {
569  // Use a tolerance of 1/256 of a pixel when converting.
570  // A float has only 24 bits of precision, so we cannot
571  // make the tolerance too small. For example, a tolerance
572  // of 2^-8 means that the tolerance will be significant
573  // for float values up to 2^16 or 65536.0. But a
574  // tolerance of 2^-16 would only be significant for
575  // float values up to 2^8 or 256.0. A small tolerance
576  // disappears into insignificance when added to a large float.
577  float tol = 0.00390625; // 1.0/256.0
578  tol = (x >= 0 ? tol : -tol);
579  return static_cast<int>(x + tol);
580 }
581 
582 #endif //vtkContext2D_h
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:47
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:345
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:39
Class for drawing 3D primitives to a graphical context.
Definition: vtkContext3D.h:40