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:
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 
85 
90 
92  void DrawLine(float x1, float y1, float x2, float y2);
93 
95  void DrawLine(float p[4]);
96 
100 
102  void DrawPoly(float *x, float *y, int n);
103 
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 
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 
140 
144  void DrawPoints(float *points, int n);
145 
150 
152 
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 
197  void DrawQuadStrip(float *p, int n);
199 
202  void DrawPolygon(float *x, float *y, int n);
203 
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);
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 
309  float height);
311 
313 
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 
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 
345 
350  void ApplyPen(vtkPen *pen);
351 
356 
361  void ApplyBrush(vtkBrush *brush);
362 
366 
371 
374 
379 
382 
388 
390 
392  void PushMatrix();
393  void PopMatrix();
395 
397  void ApplyId(vtkIdType id);
398 
402  static int FloatToInt(float x);
403 
405 
408  virtual void SetContext3D(vtkContext3D *context);
410 
411 //BTX
412 protected:
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
vtkBrush
provides a brush that fills shapes drawn by vtkContext2D.
Definition: vtkBrush.h:37
vtkPoints2D
represent and manipulate 2D points
Definition: vtkPoints2D.h:36
vtkContext2D::DrawWedge
void DrawWedge(float x, float y, float outRadius, float inRadius, float startAngle, float stopAngle)
vtkContext2D::DrawArc
void DrawArc(float x, float y, float r, float startAngle, float stopAngle)
vtkContext2D::DrawPolygon
void DrawPolygon(vtkPoints2D *points)
vtkContext2D::DrawPoints
void DrawPoints(float *points, int n)
vtkContext2D::DrawQuad
void DrawQuad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
vtkGetObjectMacro
#define vtkGetObjectMacro(name, type)
Definition: vtkSetGet.h:232
vtkContext2D::DrawMathTextString
void DrawMathTextString(vtkPoints2D *point, const vtkStdString &string, const vtkStdString &fallback)
vtkContext2D::DrawLine
void DrawLine(float x1, float y1, float x2, float y2)
vtkContext2D::ComputeStringBounds
void ComputeStringBounds(const vtkStdString &string, vtkPoints2D *bounds)
vtkgl::h
GLfloat GLfloat GLfloat GLfloat h
Definition: vtkgl.h:14364
vtkContext2D::DrawStringRect
void DrawStringRect(vtkPoints2D *rect, const vtkStdString &string)
vtkContext2D::DrawPolygon
void DrawPolygon(float *points, int n)
vtkContext2D::ApplyPen
void ApplyPen(vtkPen *pen)
vtkIdType
int vtkIdType
Definition: vtkType.h:275
vtkContext2D::DrawString
void DrawString(vtkPoints2D *point, const char *string)
VTKRENDERINGCONTEXT2D_EXPORT
#define VTKRENDERINGCONTEXT2D_EXPORT
Definition: vtkRenderingContext2DModule.h:15
vtkContext2D::PopMatrix
void PopMatrix()
vtkContext2D::New
static vtkContext2D * New()
vtkTransform2D
describes linear transformations via a 3x3 matrix
Definition: vtkTransform2D.h:47
vtkContext2D::DrawLines
void DrawLines(vtkPoints2D *points)
vtkContext2D::DrawPoly
void DrawPoly(float *points, int n, unsigned char *colors, int nc_comps)
vtkContext2D::DrawString
void DrawString(vtkPoints2D *point, const vtkUnicodeString &string)
vtkContext2D::DrawMarkers
virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D *points)
vtkgl::scale
GLenum GLenum GLenum GLenum GLenum scale
Definition: vtkgl.h:15942
vtkUnsignedCharArray
dynamic, self-adjusting array of unsigned char
Definition: vtkUnsignedCharArray.h:49
vtkContext2D::DrawMathTextString
void DrawMathTextString(float x, float y, const vtkStdString &string, const vtkStdString &fallback)
vtkTypeMacro
#define vtkTypeMacro(thisClass, superclass)
Definition: vtkSetGet.h:642
vtkgl::n
GLclampd n
Definition: vtkgl.h:14370
vtkContext2D::DrawEllipticArc
void DrawEllipticArc(float x, float y, float rX, float rY, float startAngle, float stopAngle)
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:62
vtkContext2D::ComputeFontSizeForBoundedString
int ComputeFontSizeForBoundedString(const vtkStdString &string, float width, float height)
vtkgl::x
GLint GLint GLint GLint GLint x
Definition: vtkgl.h:11318
vtkContext2D::ApplyId
void ApplyId(vtkIdType id)
vtkContext2D::DrawMathTextString
void DrawMathTextString(float x, float y, const char *string)
vtkContext2D::DrawPoint
void DrawPoint(float x, float y)
vtkContext2D
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:57
vtkContext2D::ComputeStringBounds
void ComputeStringBounds(const vtkUnicodeString &string, vtkPoints2D *bounds)
vtkContext2D::ApplyBrush
void ApplyBrush(vtkBrush *brush)
vtkgl::points
GLsizei const GLfloat * points
Definition: vtkgl.h:14786
vtkContext2D::MathTextIsSupported
bool MathTextIsSupported()
vtkContext2D::DrawLine
void DrawLine(float p[4])
vtkContext2D::SetTransform
void SetTransform(vtkTransform2D *transform)
vtkContext2D::ComputeStringBounds
void ComputeStringBounds(const char *string, float bounds[4])
vtkContext2D::DrawPoints
void DrawPoints(vtkPoints2D *points)
vtkX3D::Transform
@ Transform
Definition: vtkX3D.h:41
vtkContext2D::DrawStringRect
void DrawStringRect(vtkPoints2D *rect, const char *string)
vtkContext2D::GetTransform
vtkTransform2D * GetTransform()
vtkWindow
window superclass for vtkRenderWindow
Definition: vtkWindow.h:34
vtkContext2D::Begin
bool Begin(vtkContextDevice2D *device)
vtkContext2D::DrawMathTextString
void DrawMathTextString(float x, float y, const char *string, const char *fallback)
vtkContext2D::DrawRect
void DrawRect(float x, float y, float w, float h)
vtkAbstractContextBufferId
2D array of ids, used for picking.
Definition: vtkAbstractContextBufferId.h:46
vtkContext2D::DrawString
void DrawString(float x, float y, const vtkStdString &string)
vtkX3D::point
@ point
Definition: vtkX3D.h:236
vtkContext2D::ComputeStringBounds
void ComputeStringBounds(const vtkStdString &string, float bounds[4])
vtkContext2D::DrawLine
void DrawLine(vtkPoints2D *points)
vtkContext2D::DrawQuadStrip
void DrawQuadStrip(vtkPoints2D *points)
vtkContext2D::DrawLines
void DrawLines(float *points, int n)
vtkContext2D::PrintSelf
virtual void PrintSelf(ostream &os, vtkIndent indent)
vtkContext2D::DrawPolygon
void DrawPolygon(float *x, float *y, int n)
vtkContext2D::DrawPoints
void DrawPoints(float *x, float *y, int n)
vtkContext2D::DrawPoly
void DrawPoly(vtkPoints2D *points)
vtkContext2D::DrawEllipseWedge
void DrawEllipseWedge(float x, float y, float outRx, float outRy, float inRx, float inRy, float startAngle, float stopAngle)
vtkContext2D::DrawMathTextString
void DrawMathTextString(vtkPoints2D *point, const char *string, const char *fallback)
vtkContext2D::GetTextProp
vtkTextProperty * GetTextProp()
vtkContext2D::DrawPoly
void DrawPoly(float *points, int n)
vtkContext2D::DrawString
void DrawString(float x, float y, const vtkUnicodeString &string)
vtkContext2D::DrawMarkers
virtual void DrawMarkers(int shape, bool highlight, float *points, int n, unsigned char *colors, int nc_comps)
vtkImageData
topologically and geometrically regular array of data
Definition: vtkImageData.h:45
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkUnicodeString
String class that stores Unicode text.
Definition: vtkUnicodeString.h:72
vtkContext2D::DrawString
void DrawString(vtkPoints2D *point, const vtkStdString &string)
vtkContext2D::AppendTransform
void AppendTransform(vtkTransform2D *transform)
vtkContext2D::DrawMarkers
virtual void DrawMarkers(int shape, bool highlight, float *points, int n)
vtkX3D::startAngle
@ startAngle
Definition: vtkX3D.h:486
vtkContext2D::DrawMarkers
virtual void DrawMarkers(int shape, bool highlight, vtkPoints2D *points, vtkUnsignedCharArray *colors)
vtkContext2D::DrawImage
void DrawImage(float x, float y, vtkImageData *image)
vtkContext2D::BufferIdModeEnd
void BufferIdModeEnd()
vtkObject.h
vtkContext2D::DrawMathTextString
void DrawMathTextString(float x, float y, const vtkStdString &string)
vtkContextDevice2D
Abstract class for drawing 2D primitives.
Definition: vtkContextDevice2D.h:48
vtkTextProperty
represent text properties.
Definition: vtkTextProperty.h:39
vtkgl::width
GLint GLint GLsizei width
Definition: vtkgl.h:11316
vtkContext2D::DrawEllipse
void DrawEllipse(float x, float y, float rx, float ry)
vtkContext2D::GetBrush
vtkBrush * GetBrush()
vtkgl::r
GLdouble GLdouble GLdouble r
Definition: vtkgl.h:11610
vtkContext2D::GetPen
vtkPen * GetPen()
vtkgl::y
GLint GLint GLint GLint GLint GLint y
Definition: vtkgl.h:11318
vtkContext2D::DrawMathTextString
void DrawMathTextString(vtkPoints2D *point, const char *string)
vtkContext2D::ComputeStringBounds
void ComputeStringBounds(const char *string, vtkPoints2D *bounds)
vtkContext2D::DrawPointSprites
void DrawPointSprites(vtkImageData *sprite, vtkPoints2D *points)
vtkContext2D::DrawStringRect
void DrawStringRect(vtkPoints2D *rect, const vtkUnicodeString &string)
vtkContext2D::DrawString
void DrawString(float x, float y, const char *string)
vtkgl::p
GLfloat GLfloat p
Definition: vtkgl.h:15717
vtkContext3D
Class for drawing 3D primitives to a graphical context.
Definition: vtkContext3D.h:40
vtkContext2D::DrawMathTextString
void DrawMathTextString(vtkPoints2D *point, const vtkStdString &string)
vtkPen
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:39
vtkgl::w
GLubyte GLubyte GLubyte GLubyte w
Definition: vtkgl.h:12054
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:48
vtkContext2D::ApplyTextProp
void ApplyTextProp(vtkTextProperty *prop)
vtkgl::transform
GLuint GLenum GLenum transform
Definition: vtkgl.h:16451
vtkContext2D::ComputeStringBounds
void ComputeStringBounds(const vtkUnicodeString &string, float bounds[4])
vtkContext2D::DrawQuad
void DrawQuad(float *p)
vtkContext2D::DrawPointSprites
void DrawPointSprites(vtkImageData *sprite, vtkPoints2D *points, vtkUnsignedCharArray *colors)
vtkContext2D::DrawQuadStrip
void DrawQuadStrip(float *p, int n)
vtkContext2D::DrawPoly
void DrawPoly(float *x, float *y, int n)
vtkRenderingContext2DModule.h
vtkContext2D::DrawImage
void DrawImage(float x, float y, float scale, vtkImageData *image)
vtkContext2D::GetBufferIdMode
bool GetBufferIdMode() const
vtkRectf
Definition: vtkRect.h:97
vtkContext2D::DrawPointSprites
void DrawPointSprites(vtkImageData *sprite, float *points, int n, unsigned char *colors, int nc_comps)
vtkContext2D::DrawImage
void DrawImage(const vtkRectf &pos, vtkImageData *image)
vtkVector2f
Definition: vtkVector.h:277
vtkgl::image
GLenum GLsizei GLenum GLenum const GLvoid * image
Definition: vtkgl.h:11341
vtkContext2D::DrawPointSprites
void DrawPointSprites(vtkImageData *sprite, float *points, int n)
vtkContext2D::PushMatrix
void PushMatrix()
vtkgl::height
GLint GLint GLsizei GLsizei height
Definition: vtkgl.h:11316
vtkContext2D::End
bool End()
vtkContext2D::BufferIdModeBegin
void BufferIdModeBegin(vtkAbstractContextBufferId *bufferId)