VTK
vtkPDFContextDevice2D.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkPDFContextDevice2D.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 =========================================================================*/
20 #ifndef vtkPDFContextDevice2D_h
21 #define vtkPDFContextDevice2D_h
22 
23 #include "vtkIOExportModule.h" // For export macro
24 #include "vtkContextDevice2D.h"
25 #include "vtkNew.h" // For vtkNew!
26 
27 class vtkColor3ub;
28 class vtkPath;
29 class vtkRenderer;
30 class vtkTransform;
31 
32 class VTKIOEXPORT_EXPORT vtkPDFContextDevice2D: public vtkContextDevice2D
33 {
34 public:
35  static vtkPDFContextDevice2D* New();
37  void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE;
38 
44  void SetHaruObjects(void *doc, void *page);
45 
46  void SetRenderer(vtkRenderer*);
47 
48  void DrawPoly(float *points, int n, unsigned char *colors = 0,
49  int nc_comps = 0) VTK_OVERRIDE;
50  void DrawLines(float *f, int n, unsigned char *colors = 0,
51  int nc_comps = 0) VTK_OVERRIDE;
52  void DrawPoints(float *points, int n, unsigned char* colors = 0,
53  int nc_comps = 0) VTK_OVERRIDE;
54  void DrawPointSprites(vtkImageData *sprite, float *points, int n,
55  unsigned char *colors = 0,
56  int nc_comps = 0) VTK_OVERRIDE;
57  void DrawMarkers(int shape, bool highlight, float *points, int n,
58  unsigned char *colors = 0, int nc_comps = 0) VTK_OVERRIDE;
59  void DrawQuad(float *, int) VTK_OVERRIDE;
60  void DrawQuadStrip(float *, int) VTK_OVERRIDE;
61  void DrawPolygon(float *, int) VTK_OVERRIDE;
62  void DrawEllipseWedge(float x, float y, float outRx, float outRy,
63  float inRx, float inRy, float startAngle,
64  float stopAngle) VTK_OVERRIDE;
65  void DrawEllipticArc(float x, float y, float rX, float rY,
66  float startAngle, float stopAngle) VTK_OVERRIDE;
67  void DrawString(float *point, const vtkStdString &string) VTK_OVERRIDE;
68  void ComputeStringBounds(const vtkStdString &string,
69  float bounds[4]) VTK_OVERRIDE;
70  void DrawString(float *point, const vtkUnicodeString &string) VTK_OVERRIDE;
71  void ComputeStringBounds(const vtkUnicodeString &string,
72  float bounds[4]) VTK_OVERRIDE;
73  void ComputeJustifiedStringBounds(const char* string,
74  float bounds[4]) VTK_OVERRIDE;
75  void DrawMathTextString(float *point, const vtkStdString &str) VTK_OVERRIDE;
76  void DrawImage(float p[2], float scale, vtkImageData *image) VTK_OVERRIDE;
77  void DrawImage(const vtkRectf& pos, vtkImageData *image) VTK_OVERRIDE;
78  void DrawPolyData(float p[2], float scale, vtkPolyData* polyData,
79  vtkUnsignedCharArray* colors, int scalarMode) VTK_OVERRIDE;
80  void SetColor4(unsigned char color[4]) VTK_OVERRIDE;
81  void SetTexture(vtkImageData* image, int properties) VTK_OVERRIDE;
82  void SetPointSize(float size) VTK_OVERRIDE;
83  void SetLineWidth(float width) VTK_OVERRIDE;
84 
85  void SetLineType(int type) VTK_OVERRIDE;
86  void SetMatrix(vtkMatrix3x3 *m) VTK_OVERRIDE;
87  void GetMatrix(vtkMatrix3x3 *m) VTK_OVERRIDE;
88  void MultiplyMatrix(vtkMatrix3x3 *m) VTK_OVERRIDE;
89  void PushMatrix() VTK_OVERRIDE;
90  void PopMatrix() VTK_OVERRIDE;
91  void SetClipping(int *x) VTK_OVERRIDE;
92  void EnableClipping(bool enable) VTK_OVERRIDE;
93 
94 protected:
96  ~vtkPDFContextDevice2D() VTK_OVERRIDE;
97 
98  void PushGraphicsState();
99  void PopGraphicsState();
100 
101  void ApplyPenState();
102  void ApplyStrokeColor(unsigned char *color, int numComps);
103  void ApplyLineWidth(float width);
104  void ApplyLineType(int type);
105  void Stroke();
106 
107  void ApplyPenStateAsFill();
108  void ApplyBrushState();
109  void ApplyTextPropertyState();
110  void ApplyFillColor(unsigned char *color, int numComps);
111  void ApplyFillAlpha(unsigned char alpha);
112  void Fill(bool stroke = false);
113  void FillEvenOdd(bool stroke = false);
114 
115  void BeginClipPathForTexture();
116  void RegisterTexturePoints(float *data, int numPoints);
117  void FillTexture();
118 
119  // converts input to RGB if needed. Call Delete() on the returned object when
120  // finished with it.
121  vtkImageData* PrepareImageData(vtkImageData *in);
122 
123  void DrawEllipticArcSegments(float x, float y, float rX, float rY,
124  float startAngle, float stopAngle,
125  bool startPath);
126  int GetNumberOfArcIterations(float rX, float rY,
127  float startAngle, float stopAngle);
128 
129  void DrawCrossMarkers(bool highlight, float *points, int n,
130  unsigned char *colors, int nc_comps);
131  void DrawPlusMarkers(bool highlight, float *points, int n,
132  unsigned char *colors, int nc_comps);
133  void DrawSquareMarkers(bool highlight, float *points, int n,
134  unsigned char *colors, int nc_comps);
135  void DrawCircleMarkers(bool highlight, float *points, int n,
136  unsigned char *colors, int nc_comps);
137  void DrawDiamondMarkers(bool highlight, float *points, int n,
138  unsigned char *colors, int nc_comps);
139 
140  void DrawPath(vtkPath *path, float x, float y);
141 
142  void BeginText();
143  float ComputeTextWidth(const vtkStdString &str);
144  // Transforms pos form the VTK anchor point to the PDF anchor point, and
145  // returns a guess at the height of the rendered string.
146  // realWidth is the width computed by ComputTextWidth.
147  float ComputeTextPosition(float pos[2], const vtkStdString &str,
148  float realWidth);
149  void AlignText(double orientation, float width, float height, float *p);
150  void EndText();
151 
152  void ApplyTransform();
153 
154  // Converts a 2D transform matrix into a 3D transform matrix, or vice versa
155  static void Matrix3ToMatrix4(vtkMatrix3x3 *mat3, double mat4[16]);
156  static void Matrix4ToMatrix3(double mat4[16], vtkMatrix3x3 *mat3);
157 
158  // Convert a 3D transform matrix to an HPDF transformation.
159  // trans = {a, b, c, d, x, y}, which define the transform:
160  // | a b x |
161  // | c d y |
162  // | 0 0 1 |
163  static void Matrix4ToHPDFTransform(const double mat4[16], float hpdfMat[6]);
164  static void Matrix3ToHPDFTransform(const double mat4[9], float hpdfMat[6]);
165  static void HPDFTransformToMatrix3(float a, float b, float c, float d,
166  float x, float y, double mat3[9]);
167 
168  struct Details;
169  Details *Impl;
170 
171  // This is a 3D transform, the 2D version doesn't support push/pop.
173 
174  vtkRenderer *Renderer;
175  float PointSize;
176  bool IsClipping;
177  float ClipBox[4]; // x, y, w, h
178 
179  bool IsInTexturedFill;
180  float TextureBounds[4]; // xmin, xmax, ymin, ymax; used for placing textures
181 
182 private:
183  vtkPDFContextDevice2D(const vtkPDFContextDevice2D&) VTK_DELETE_FUNCTION;
184  void operator=(const vtkPDFContextDevice2D&) VTK_DELETE_FUNCTION;
185 };
186 
187 #endif // vtkPDFContextDevice2D_h
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:47
concrete dataset representing a path defined by Bezier curves.
Definition: vtkPath.h:35
abstract specification for renderers
Definition: vtkRenderer.h:63
static vtkContextDevice2D * New()
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:60
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:85
virtual void DrawPoly(float *points, int n, unsigned char *colors=0, int nc_comps=0)=0
Draw a poly line using the points - fastest code path due to memory layout of the coordinates...
Some derived classes for the different colors commonly used.
Definition: vtkColor.h:194
a simple class to control print indentation
Definition: vtkIndent.h:39
topologically and geometrically regular array of data
Definition: vtkImageData.h:45
Abstract class for drawing 2D primitives.
vtkContextDevice2D implementation for use with vtkPDFExporter.
dynamic, self-adjusting array of unsigned char
Allocate and hold a VTK object.
Definition: vtkNew.h:67
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:36
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
String class that stores Unicode text.