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 
294  void ComputeStringBounds(const vtkStdString &string, vtkPoints2D *bounds);
295  void ComputeStringBounds(const vtkStdString &string, float bounds[4]);
296  void ComputeStringBounds(const vtkUnicodeString &string, vtkPoints2D *bounds);
297  void ComputeStringBounds(const vtkUnicodeString &string, float bounds[4]);
298  void ComputeStringBounds(const char* string, vtkPoints2D *bounds);
299  void ComputeStringBounds(const char* string, float bounds[4]);
301 
303 
308  int ComputeFontSizeForBoundedString(const vtkStdString &string, float width,
309  float height);
311 
313 
319  void DrawMathTextString(vtkPoints2D *point, const vtkStdString &string);
320  void DrawMathTextString(float x, float y, const vtkStdString &string);
321  void DrawMathTextString(vtkPoints2D *point, const char *string);
322  void DrawMathTextString(float x, float y, const char *string);
324 
326 
332  void DrawMathTextString(vtkPoints2D *point, const vtkStdString &string,
333  const vtkStdString &fallback);
334  void DrawMathTextString(float x, float y, const vtkStdString &string,
335  const vtkStdString &fallback);
336  void DrawMathTextString(vtkPoints2D *point, const char *string,
337  const char *fallback);
338  void DrawMathTextString(float x, float y, const char *string,
339  const char *fallback);
341 
342 
344  bool MathTextIsSupported();
345 
350  void ApplyPen(vtkPen *pen);
351 
355  vtkPen* GetPen();
356 
361  void ApplyBrush(vtkBrush *brush);
362 
365  vtkBrush* GetBrush();
366 
370  void ApplyTextProp(vtkTextProperty *prop);
371 
373  vtkTextProperty* GetTextProp();
374 
378  void SetTransform(vtkTransform2D *transform);
379 
381  vtkTransform2D* GetTransform();
382 
387  void AppendTransform(vtkTransform2D *transform);
388 
390 
392  void PushMatrix();
393  void PopMatrix();
395 
397  void ApplyId(vtkIdType id);
398 
402  static int FloatToInt(float x);
403 
405 
407  vtkGetObjectMacro(Context3D, vtkContext3D)
408  virtual void SetContext3D(vtkContext3D *context);
410 
411 //BTX
412 protected:
413  vtkContext2D();
414  ~vtkContext2D();
415 
416  vtkContextDevice2D *Device; // The underlying device
417  vtkTransform2D *Transform; // Current transform
418 
420  vtkContext3D *Context3D; // May be very temporary - get at a 3D version.
421 
422 private:
423  vtkContext2D(const vtkContext2D &); // Not implemented.
424  void operator=(const vtkContext2D &); // Not implemented.
425 
427  vtkVector2f CalculateTextPosition(vtkPoints2D* rect);
428 
429 //ETX
430 };
431 
432 inline int vtkContext2D::FloatToInt(float x)
433 {
434  // Use a tolerance of 1/256 of a pixel when converting.
435  // A float has only 24 bits of precision, so we cannot
436  // make the tolerance too small. For example, a tolerance
437  // of 2^-8 means that the tolerance will be significant
438  // for float values up to 2^16 or 65536.0. But a
439  // tolerance of 2^-16 would only be significant for
440  // float values up to 2^8 or 256.0. A small tolerance
441  // disappears into insignificance when added to a large float.
442  float tol = 0.00390625; // 1.0/256.0
443  tol = (x >= 0 ? tol : -tol);
444  return static_cast<int>(x + tol);
445 }
446 
447 #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:275
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