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) 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 = nullptr,
49  int nc_comps = 0) override;
50  void DrawLines(float *f, int n, unsigned char *colors = nullptr,
51  int nc_comps = 0) override;
52  void DrawPoints(float *points, int n, unsigned char* colors = nullptr,
53  int nc_comps = 0) override;
54  void DrawPointSprites(vtkImageData *sprite, float *points, int n,
55  unsigned char *colors = nullptr,
56  int nc_comps = 0) override;
57  void DrawMarkers(int shape, bool highlight, float *points, int n,
58  unsigned char *colors = nullptr, int nc_comps = 0) override;
59  void DrawQuad(float *, int) override;
60  void DrawQuadStrip(float *, int) override;
61  void DrawPolygon(float *, int) override;
62  void DrawColoredPolygon(float *points, int numPoints,
63  unsigned char *colors = nullptr,
64  int nc_comps = 0) override;
65  void DrawEllipseWedge(float x, float y, float outRx, float outRy,
66  float inRx, float inRy, float startAngle,
67  float stopAngle) override;
68  void DrawEllipticArc(float x, float y, float rX, float rY,
69  float startAngle, float stopAngle) override;
70  void DrawString(float *point, const vtkStdString &string) override;
71  void ComputeStringBounds(const vtkStdString &string,
72  float bounds[4]) override;
73  void DrawString(float *point, const vtkUnicodeString &string) override;
74  void ComputeStringBounds(const vtkUnicodeString &string,
75  float bounds[4]) override;
76  void ComputeJustifiedStringBounds(const char* string,
77  float bounds[4]) override;
78  void DrawMathTextString(float *point, const vtkStdString &str) override;
79  void DrawImage(float p[2], float scale, vtkImageData *image) override;
80  void DrawImage(const vtkRectf& pos, vtkImageData *image) override;
81  void SetColor4(unsigned char color[4]) override;
82  void SetTexture(vtkImageData* image, int properties) override;
83  void SetPointSize(float size) override;
84  void SetLineWidth(float width) override;
85  void DrawPolyData(float p[2], float scale, vtkPolyData* polyData,
86  vtkUnsignedCharArray* colors, int scalarMode) override;
87 
88  void SetLineType(int type) override;
89  void SetMatrix(vtkMatrix3x3 *m) override;
90  void GetMatrix(vtkMatrix3x3 *m) override;
91  void MultiplyMatrix(vtkMatrix3x3 *m) override;
92  void PushMatrix() override;
93  void PopMatrix() override;
94  void SetClipping(int *x) override;
95  void EnableClipping(bool enable) override;
96 
97 protected:
99  ~vtkPDFContextDevice2D() override;
100 
101  void PushGraphicsState();
102  void PopGraphicsState();
103 
104  void ApplyPenState();
105  void ApplyStrokeColor(unsigned char *color, int numComps);
106  void ApplyLineWidth(float width);
107  void ApplyLineType(int type);
108  void Stroke();
109 
110  void ApplyPenStateAsFill();
111  void ApplyBrushState();
112  void ApplyTextPropertyState();
113  void ApplyFillColor(unsigned char *color, int numComps);
114  void ApplyFillAlpha(unsigned char alpha);
115  void Fill(bool stroke = false);
116  void FillEvenOdd(bool stroke = false);
117 
118  void BeginClipPathForTexture();
119  void RegisterTexturePoints(float *data, int numPoints);
120  void FillTexture();
121 
122  // converts input to RGB if needed. Call Delete() on the returned object when
123  // finished with it.
124  vtkImageData* PrepareImageData(vtkImageData *in);
125 
126  void DrawEllipticArcSegments(float x, float y, float rX, float rY,
127  float startAngle, float stopAngle,
128  bool startPath);
129  int GetNumberOfArcIterations(float rX, float rY,
130  float startAngle, float stopAngle);
131 
132  void DrawCrossMarkers(bool highlight, float *points, int n,
133  unsigned char *colors, int nc_comps);
134  void DrawPlusMarkers(bool highlight, float *points, int n,
135  unsigned char *colors, int nc_comps);
136  void DrawSquareMarkers(bool highlight, float *points, int n,
137  unsigned char *colors, int nc_comps);
138  void DrawCircleMarkers(bool highlight, float *points, int n,
139  unsigned char *colors, int nc_comps);
140  void DrawDiamondMarkers(bool highlight, float *points, int n,
141  unsigned char *colors, int nc_comps);
142 
143  void DrawPath(vtkPath *path, float x, float y);
144 
145  void BeginText();
146  float ComputeTextWidth(const vtkStdString &str);
147  // Transforms pos form the VTK anchor point to the PDF anchor point, and
148  // returns a guess at the height of the rendered string.
149  // realWidth is the width computed by ComputTextWidth.
150  float ComputeTextPosition(float pos[2], const vtkStdString &str,
151  float realWidth);
152  void AlignText(double orientation, float width, float height, float *p);
153  void EndText();
154 
155  void ApplyTransform();
156 
157  // Converts a 2D transform matrix into a 3D transform matrix, or vice versa
158  static void Matrix3ToMatrix4(vtkMatrix3x3 *mat3, double mat4[16]);
159  static void Matrix4ToMatrix3(double mat4[16], vtkMatrix3x3 *mat3);
160  static void Matrix4ToMatrix3(double mat4[16], double mat3[9]);
161 
162  // Convert a 3D transform matrix to an HPDF transformation.
163  // trans = {a, b, c, d, x, y}, which define the transform:
164  // | a b x |
165  // | c d y |
166  // | 0 0 1 |
167  static void Matrix4ToHPDFTransform(const double mat4[16], float hpdfMat[6]);
168  static void Matrix3ToHPDFTransform(const double mat4[9], float hpdfMat[6]);
169  static void HPDFTransformToMatrix3(float a, float b, float c, float d,
170  float x, float y, double mat3[9]);
171 
172  struct Details;
173  Details *Impl;
174 
175  // This is a 3D transform, the 2D version doesn't support push/pop.
177 
179  float PointSize;
180  float ClipBox[4]; // x, y, w, h
181 
183  float TextureBounds[4]; // xmin, xmax, ymin, ymax; used for placing textures
184 
185 private:
187  void operator=(const vtkPDFContextDevice2D&) = delete;
188 };
189 
190 #endif // vtkPDFContextDevice2D_h
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:40
virtual void SetMatrix(vtkMatrix3x3 *m)=0
Set the model view matrix for the display.
virtual void DrawPointSprites(vtkImageData *sprite, float *points, int n, unsigned char *colors=nullptr, int nc_comps=0)=0
Draw a series of point sprites, images centred at the points supplied.
virtual void SetClipping(int *x)=0
Supply a float array of length 4 with x1, y1, width, height specifying clipping region for the device...
virtual void ComputeJustifiedStringBounds(const char *string, float bounds[4])=0
Compute the bounds of the supplied string while taking into account the justification of the currentl...
virtual void DrawPoly(float *points, int n, unsigned char *colors=nullptr, int nc_comps=0)=0
Draw a poly line using the points - fastest code path due to memory layout of the coordinates...
concrete dataset representing a path defined by Bezier curves.
Definition: vtkPath.h:35
virtual void DrawPolygon(float *p, int n)
Draw a polygon using the specified number of points.
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 DrawPolyData(float p[2], float scale, vtkPolyData *polyData, vtkUnsignedCharArray *colors, int scalarMode)
Draw the supplied PolyData at the given x, y (p[0], p[1]) (bottom corner), scaled by scale (1...
virtual void SetColor4(unsigned char color[4])=0
Set the color for the device using unsigned char of length 4, RGBA.
virtual void EnableClipping(bool enable)=0
Enable or disable the clipping of the scene.
virtual void SetLineWidth(float width)=0
Set the line width.
virtual void DrawPoints(float *points, int n, unsigned char *colors=nullptr, int nc_comps=0)=0
Draw a series of 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
virtual void DrawMarkers(int shape, bool highlight, float *points, int n, unsigned char *colors=nullptr, int nc_comps=0)
Draw a series of markers centered at the points supplied.
topologically and geometrically regular array of data
Definition: vtkImageData.h:45
virtual void DrawQuadStrip(float *, int)
Draw a quad using the specified number of points.
Abstract class for drawing 2D primitives.
virtual void PopMatrix()=0
Pop the current matrix off of the stack.
virtual void DrawLines(float *f, int n, unsigned char *colors=nullptr, int nc_comps=0)=0
Draw lines using the points - memory layout is as follows: l1p1,l1p2,l2p1,l2p2... ...
virtual void SetTexture(vtkImageData *image, int properties)=0
Set the texture for the device, it is used to fill the polygons.
vtkContextDevice2D implementation for use with vtkPDFExporter.
virtual void DrawMathTextString(float *point, const vtkStdString &string)=0
Draw text using MathText markup for mathematical equations.
virtual void SetPointSize(float size)=0
Set the point size for glyphs/sprites.
dynamic, self-adjusting array of unsigned char
virtual void DrawQuad(float *, int)
Draw a quad using the specified number of points.
virtual void DrawEllipticArc(float x, float y, float rX, float rY, float startAngle, float stopAngle)=0
Draw an elliptic arc with center at x,y with radii rX and rY between angles startAngle and stopAngle ...
virtual void MultiplyMatrix(vtkMatrix3x3 *m)=0
Multiply the current model view matrix by the supplied one.
virtual void DrawString(float *point, const vtkStdString &string)=0
Draw some text to the screen.
virtual void DrawEllipseWedge(float x, float y, float outRx, float outRy, float inRx, float inRy, float startAngle, float stopAngle)=0
Draw an elliptic wedge with center at x, y, outer radii outRx, outRy, inner radii inRx...
virtual void DrawColoredPolygon(float *points, int numPoints, unsigned char *colors=nullptr, int nc_comps=0)
Draw a polygon using the specified number of points.
virtual void GetMatrix(vtkMatrix3x3 *m)=0
Set the model view matrix for the display.
virtual void ComputeStringBounds(const vtkStdString &string, float bounds[4])=0
Compute the bounds of the supplied string.
virtual void PushMatrix()=0
Push the current matrix onto the stack.
virtual void DrawImage(float p[2], float scale, vtkImageData *image)=0
Draw the supplied image at the given x, y (p[0], p[1]) (bottom corner), scaled by scale (1...
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:36
virtual void SetLineType(int type)=0
Set the line type type (using anonymous enum in vtkPen).
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.
vtkNew< vtkTransform > Matrix