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 
32 #ifndef vtkContext2D_h
33 #define vtkContext2D_h
34 
35 #include "vtkRenderingContext2DModule.h" // For export macro
36 #include "vtkObject.h"
37 
38 class vtkWindow;
39 
40 class vtkContext3D;
41 class vtkStdString;
42 class vtkUnicodeString;
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 vtkTransform2D;
55 
57 {
58 public:
59  vtkTypeMacro(vtkContext2D, vtkObject);
60  virtual void PrintSelf(ostream &os, vtkIndent indent);
61 
63  static vtkContext2D *New();
64 
65 //BTX
69  bool Begin(vtkContextDevice2D *device);
70 
71  vtkGetObjectMacro(Device, vtkContextDevice2D);
72 
76  bool End();
77 
80  bool GetBufferIdMode() const;
81 
84  void BufferIdModeBegin(vtkAbstractContextBufferId *bufferId);
85 
89  void BufferIdModeEnd();
90 
92  void DrawLine(float x1, float y1, float x2, float y2);
93 
95  void DrawLine(float p[4]);
96 
99  void DrawLine(vtkPoints2D *points);
100 
102  void DrawPoly(float *x, float *y, int n);
103 
106  void DrawPoly(vtkPoints2D *points);
107 
111  void DrawPoly(float *points, int n);
112 
114 
119  void DrawPoly(float *points, int n,
120  unsigned char *colors, int nc_comps);
122 
125  void DrawLines(vtkPoints2D *points);
126 
129  void DrawLines(float *points, int n);
130 
132  void DrawPoint(float x, float y);
133 
135  void DrawPoints(float *x, float *y, int n);
136 
139  void DrawPoints(vtkPoints2D *points);
140 
144  void DrawPoints(float *points, int n);
145 
149  void DrawPointSprites(vtkImageData *sprite, vtkPoints2D *points);
150 
152 
157  void DrawPointSprites(vtkImageData *sprite, vtkPoints2D *points,
158  vtkUnsignedCharArray *colors);
159  void DrawPointSprites(vtkImageData *sprite, float *points, int n,
160  unsigned char *colors, int nc_comps);
162 
166  void DrawPointSprites(vtkImageData *sprite, float *points, int n);
167 
169 
175  virtual void DrawMarkers(int shape, bool highlight, float *points, int n,
176  unsigned char *colors, int nc_comps);
177  virtual void DrawMarkers(int shape, bool highlight, float *points, int n);
178  virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D *points);
179  virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D *points,
180  vtkUnsignedCharArray *colors);
182 
184  void DrawRect(float x, float y, float w, float h);
185 
187 
189  void DrawQuad(float x1, float y1, float x2, float y2,
190  float x3, float y3, float x4, float y4);
191  void DrawQuad(float *p);
193 
195 
196  void DrawQuadStrip(vtkPoints2D *points);
197  void DrawQuadStrip(float *p, int n);
199 
202  void DrawPolygon(float *x, float *y, int n);
203 
206  void DrawPolygon(vtkPoints2D *points);
207 
211  void DrawPolygon(float *points, int n);
212 
215  void DrawEllipse(float x, float y, float rx, float ry);
216 
218 
223  void DrawWedge(float x, float y, float outRadius,
224  float inRadius,float startAngle,
225  float stopAngle);
227 
229 
235  void DrawEllipseWedge(float x, float y, float outRx, float outRy,
236  float inRx, float inRy, float startAngle,
237  float stopAngle);
239 
240 
242 
245  void DrawArc(float x, float y, float r, float startAngle,
246  float stopAngle);
248 
250 
253  void DrawEllipticArc(float x, float y, float rX, float rY, float startAngle,
254  float stopAngle);
256 
257 
259  void DrawImage(float x, float y, vtkImageData *image);
260 
263  void DrawImage(float x, float y, float scale, vtkImageData *image);
264 
268  void DrawImage(const vtkRectf& pos, vtkImageData *image);
269 
271 
274  void DrawStringRect(vtkPoints2D *rect, const vtkStdString &string);
275  void DrawStringRect(vtkPoints2D *rect, const vtkUnicodeString &string);
276  void DrawStringRect(vtkPoints2D *rect, const char* string);
278 
280 
281  void DrawString(vtkPoints2D *point, const vtkStdString &string);
282  void DrawString(float x, float y, const vtkStdString &string);
283  void DrawString(vtkPoints2D *point, const vtkUnicodeString &string);
284  void DrawString(float x, float y, const vtkUnicodeString &string);
285  void DrawString(vtkPoints2D *point, const char* string);
286  void DrawString(float x, float y, const char* string);
288 
290 
296  void ComputeStringBounds(const vtkStdString &string, vtkPoints2D *bounds);
297  void ComputeStringBounds(const vtkStdString &string, float bounds[4]);
298  void ComputeStringBounds(const vtkUnicodeString &string, vtkPoints2D *bounds);
299  void ComputeStringBounds(const vtkUnicodeString &string, float bounds[4]);
300  void ComputeStringBounds(const char* string, vtkPoints2D *bounds);
301  void ComputeStringBounds(const char* string, float bounds[4]);
303 
306  void ComputeJustifiedStringBounds(const char* string, float bounds[4]);
307 
309 
314  int ComputeFontSizeForBoundedString(const vtkStdString &string, float width,
315  float height);
317 
319 
325  void DrawMathTextString(vtkPoints2D *point, const vtkStdString &string);
326  void DrawMathTextString(float x, float y, const vtkStdString &string);
327  void DrawMathTextString(vtkPoints2D *point, const char *string);
328  void DrawMathTextString(float x, float y, const char *string);
330 
332 
338  void DrawMathTextString(vtkPoints2D *point, const vtkStdString &string,
339  const vtkStdString &fallback);
340  void DrawMathTextString(float x, float y, const vtkStdString &string,
341  const vtkStdString &fallback);
342  void DrawMathTextString(vtkPoints2D *point, const char *string,
343  const char *fallback);
344  void DrawMathTextString(float x, float y, const char *string,
345  const char *fallback);
347 
348 
350  bool MathTextIsSupported();
351 
356  void ApplyPen(vtkPen *pen);
357 
361  vtkPen* GetPen();
362 
367  void ApplyBrush(vtkBrush *brush);
368 
371  vtkBrush* GetBrush();
372 
376  void ApplyTextProp(vtkTextProperty *prop);
377 
379  vtkTextProperty* GetTextProp();
380 
384  void SetTransform(vtkTransform2D *transform);
385 
387  vtkTransform2D* GetTransform();
388 
393  void AppendTransform(vtkTransform2D *transform);
394 
396 
398  void PushMatrix();
399  void PopMatrix();
401 
403  void ApplyId(vtkIdType id);
404 
408  static int FloatToInt(float x);
409 
411 
413  vtkGetObjectMacro(Context3D, vtkContext3D)
414  virtual void SetContext3D(vtkContext3D *context);
416 
417 //BTX
418 protected:
419  vtkContext2D();
420  ~vtkContext2D();
421 
422  vtkContextDevice2D *Device; // The underlying device
423  vtkTransform2D *Transform; // Current transform
424 
426  vtkContext3D *Context3D; // May be very temporary - get at a 3D version.
427 
428 private:
429  vtkContext2D(const vtkContext2D &); // Not implemented.
430  void operator=(const vtkContext2D &); // Not implemented.
431 
435  vtkVector2f CalculateTextPosition(vtkPoints2D* rect);
436 
440  vtkVector2f CalculateTextPosition(float rect[4]);
441 
442 //ETX
443 };
444 
445 inline int vtkContext2D::FloatToInt(float x)
446 {
447  // Use a tolerance of 1/256 of a pixel when converting.
448  // A float has only 24 bits of precision, so we cannot
449  // make the tolerance too small. For example, a tolerance
450  // of 2^-8 means that the tolerance will be significant
451  // for float values up to 2^16 or 65536.0. But a
452  // tolerance of 2^-16 would only be significant for
453  // float values up to 2^8 or 256.0. A small tolerance
454  // disappears into insignificance when added to a large float.
455  float tol = 0.00390625; // 1.0/256.0
456  tol = (x >= 0 ? tol : -tol);
457  return static_cast<int>(x + tol);
458 }
459 
460 #endif //vtkContext2D_h
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:46
abstract base class for most VTK objects
Definition: vtkObject.h:61
int vtkIdType
Definition: vtkType.h:247
window superclass for vtkRenderWindow
Definition: vtkWindow.h:36
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:56
provides a brush that fills shapes drawn by vtkContext2D.
Definition: vtkBrush.h:36
virtual void PrintSelf(ostream &os, vtkIndent indent)
#define VTKRENDERINGCONTEXT2D_EXPORT
a simple class to control print indentation
Definition: vtkIndent.h:38
represent and manipulate 2D points
Definition: vtkPoints2D.h:35
topologically and geometrically regular array of data
Definition: vtkImageData.h:44
Abstract class for drawing 2D primitives.
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:38
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()
String class that stores Unicode text.
Class for drawing 3D primitives to a graphical context.
Definition: vtkContext3D.h:39