VTK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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:
60  virtual void PrintSelf(ostream &os, vtkIndent indent);
61 
63  static vtkContext2D *New();
64 
65 //BTX
69  bool Begin(vtkContextDevice2D *device);
70 
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 
124  void DrawPoint(float x, float y);
125 
127  void DrawPoints(float *x, float *y, int n);
128 
131  void DrawPoints(vtkPoints2D *points);
132 
136  void DrawPoints(float *points, int n);
137 
141  void DrawPointSprites(vtkImageData *sprite, vtkPoints2D *points);
142 
144 
149  void DrawPointSprites(vtkImageData *sprite, vtkPoints2D *points,
150  vtkUnsignedCharArray *colors);
151  void DrawPointSprites(vtkImageData *sprite, float *points, int n,
152  unsigned char *colors, int nc_comps);
154 
158  void DrawPointSprites(vtkImageData *sprite, float *points, int n);
159 
161 
167  virtual void DrawMarkers(int shape, bool highlight, float *points, int n,
168  unsigned char *colors, int nc_comps);
169  virtual void DrawMarkers(int shape, bool highlight, float *points, int n);
170  virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D *points);
171  virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D *points,
172  vtkUnsignedCharArray *colors);
174 
176  void DrawRect(float x, float y, float w, float h);
177 
179 
181  void DrawQuad(float x1, float y1, float x2, float y2,
182  float x3, float y3, float x4, float y4);
183  void DrawQuad(float *p);
185 
187 
188  void DrawQuadStrip(vtkPoints2D *points);
189  void DrawQuadStrip(float *p, int n);
191 
194  void DrawPolygon(float *x, float *y, int n);
195 
198  void DrawPolygon(vtkPoints2D *points);
199 
203  void DrawPolygon(float *points, int n);
204 
207  void DrawEllipse(float x, float y, float rx, float ry);
208 
210 
215  void DrawWedge(float x, float y, float outRadius,
216  float inRadius,float startAngle,
217  float stopAngle);
219 
221 
227  void DrawEllipseWedge(float x, float y, float outRx, float outRy,
228  float inRx, float inRy, float startAngle,
229  float stopAngle);
231 
232 
234 
237  void DrawArc(float x, float y, float r, float startAngle,
238  float stopAngle);
240 
242 
245  void DrawEllipticArc(float x, float y, float rX, float rY, float startAngle,
246  float stopAngle);
248 
249 
251  void DrawImage(float x, float y, vtkImageData *image);
252 
255  void DrawImage(float x, float y, float scale, vtkImageData *image);
256 
260  void DrawImage(const vtkRectf& pos, vtkImageData *image);
261 
263 
266  void DrawStringRect(vtkPoints2D *rect, const vtkStdString &string);
267  void DrawStringRect(vtkPoints2D *rect, const vtkUnicodeString &string);
268  void DrawStringRect(vtkPoints2D *rect, const char* string);
270 
272 
273  void DrawString(vtkPoints2D *point, const vtkStdString &string);
274  void DrawString(float x, float y, const vtkStdString &string);
275  void DrawString(vtkPoints2D *point, const vtkUnicodeString &string);
276  void DrawString(float x, float y, const vtkUnicodeString &string);
277  void DrawString(vtkPoints2D *point, const char* string);
278  void DrawString(float x, float y, const char* string);
280 
282 
286  void ComputeStringBounds(const vtkStdString &string, vtkPoints2D *bounds);
287  void ComputeStringBounds(const vtkStdString &string, float bounds[4]);
288  void ComputeStringBounds(const vtkUnicodeString &string, vtkPoints2D *bounds);
289  void ComputeStringBounds(const vtkUnicodeString &string, float bounds[4]);
290  void ComputeStringBounds(const char* string, vtkPoints2D *bounds);
291  void ComputeStringBounds(const char* string, float bounds[4]);
293 
295 
300  int ComputeFontSizeForBoundedString(const vtkStdString &string, float width,
301  float height);
303 
305 
311  void DrawMathTextString(vtkPoints2D *point, const vtkStdString &string);
312  void DrawMathTextString(float x, float y, const vtkStdString &string);
313  void DrawMathTextString(vtkPoints2D *point, const char *string);
314  void DrawMathTextString(float x, float y, const char *string);
316 
318 
324  void DrawMathTextString(vtkPoints2D *point, const vtkStdString &string,
325  const vtkStdString &fallback);
326  void DrawMathTextString(float x, float y, const vtkStdString &string,
327  const vtkStdString &fallback);
328  void DrawMathTextString(vtkPoints2D *point, const char *string,
329  const char *fallback);
330  void DrawMathTextString(float x, float y, const char *string,
331  const char *fallback);
333 
334 
336  bool MathTextIsSupported();
337 
342  void ApplyPen(vtkPen *pen);
343 
347  vtkPen* GetPen();
348 
353  void ApplyBrush(vtkBrush *brush);
354 
357  vtkBrush* GetBrush();
358 
362  void ApplyTextProp(vtkTextProperty *prop);
363 
365  vtkTextProperty* GetTextProp();
366 
370  void SetTransform(vtkTransform2D *transform);
371 
373  vtkTransform2D* GetTransform();
374 
379  void AppendTransform(vtkTransform2D *transform);
380 
382 
384  void PushMatrix();
385  void PopMatrix();
387 
389  void ApplyId(vtkIdType id);
390 
394  static int FloatToInt(float x);
395 
397 
399  vtkGetObjectMacro(Context3D, vtkContext3D)
400  virtual void SetContext3D(vtkContext3D *context);
402 
403 //BTX
404 protected:
405  vtkContext2D();
406  ~vtkContext2D();
407 
408  vtkContextDevice2D *Device; // The underlying device
409  vtkTransform2D *Transform; // Current transform
410 
412  vtkContext3D *Context3D; // May be very temporary - get at a 3D version.
413 
414 private:
415  vtkContext2D(const vtkContext2D &); // Not implemented.
416  void operator=(const vtkContext2D &); // Not implemented.
417 
419  vtkVector2f CalculateTextPosition(vtkPoints2D* rect);
420 
421 //ETX
422 };
423 
424 inline int vtkContext2D::FloatToInt(float x)
425 {
426  // Use a tolerance of 1/256 of a pixel when converting.
427  // A float has only 24 bits of precision, so we cannot
428  // make the tolerance too small. For example, a tolerance
429  // of 2^-8 means that the tolerance will be significant
430  // for float values up to 2^16 or 65536.0. But a
431  // tolerance of 2^-16 would only be significant for
432  // float values up to 2^8 or 256.0. A small tolerance
433  // disappears into insignificance when added to a large float.
434  float tol = 0.00390625; // 1.0/256.0
435  tol = (x >= 0 ? tol : -tol);
436  return static_cast<int>(x + tol);
437 }
438 
439 #endif //__vtkContext2D_h
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:46
GLuint GLenum GLenum transform
Definition: vtkgl.h:16451
abstract base class for most VTK objects
Definition: vtkObject.h:61
GLenum GLsizei GLenum GLenum const GLvoid * image
Definition: vtkgl.h:11341
GLenum GLenum GLenum GLenum GLenum scale
Definition: vtkgl.h:15942
int vtkIdType
Definition: vtkType.h:268
GLdouble GLdouble GLdouble r
Definition: vtkgl.h:11610
GLint GLint GLint GLint GLint GLint y
Definition: vtkgl.h:11318
#define vtkTypeMacro(thisClass, superclass)
Definition: vtkSetGet.h:619
GLint GLint GLsizei GLsizei height
Definition: vtkgl.h:11316
window superclass for vtkRenderWindow
Definition: vtkWindow.h:33
GLint GLint GLint GLint GLint x
Definition: vtkgl.h:11318
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:56
GLubyte GLubyte GLubyte GLubyte w
Definition: vtkgl.h:12054
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
GLint GLint GLsizei width
Definition: vtkgl.h:11316
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.
#define vtkGetObjectMacro(name, type)
Definition: vtkSetGet.h:222
dynamic, self-adjusting array of unsigned char
2D array of ids, used for picking.
GLsizei const GLfloat * points
Definition: vtkgl.h:14786
GLclampd n
Definition: vtkgl.h:14370
static vtkObject * New()
GLfloat GLfloat GLfloat GLfloat h
Definition: vtkgl.h:14364
String class that stores Unicode text.
GLfloat GLfloat p
Definition: vtkgl.h:15717
Class for drawing 3D primitives to a graphical context.
Definition: vtkContext3D.h:39