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 =========================================================================*/
25 #ifndef vtkPDFContextDevice2D_h
26 #define vtkPDFContextDevice2D_h
27 
28 #include "vtkIOExportPDFModule.h" // For export macro
29 #include "vtkContextDevice2D.h"
30 #include "vtkNew.h" // For vtkNew!
31 
32 class vtkColor3ub;
33 class vtkPath;
34 class vtkRenderer;
35 class vtkTransform;
36 
37 class VTKIOEXPORTPDF_EXPORT vtkPDFContextDevice2D: public vtkContextDevice2D
38 {
39 public:
40  static vtkPDFContextDevice2D* New();
42  void PrintSelf(ostream &os, vtkIndent indent) override;
43 
49  void SetHaruObjects(void *doc, void *page);
50 
51  void SetRenderer(vtkRenderer*);
52 
53  void DrawPoly(float *points, int n, unsigned char *colors = nullptr,
54  int nc_comps = 0) override;
55  void DrawLines(float *f, int n, unsigned char *colors = nullptr,
56  int nc_comps = 0) override;
57  void DrawPoints(float *points, int n, unsigned char* colors = nullptr,
58  int nc_comps = 0) override;
59  void DrawPointSprites(vtkImageData *sprite, float *points, int n,
60  unsigned char *colors = nullptr,
61  int nc_comps = 0) override;
62  void DrawMarkers(int shape, bool highlight, float *points, int n,
63  unsigned char *colors = nullptr, int nc_comps = 0) override;
64  void DrawQuad(float *, int) override;
65  void DrawQuadStrip(float *, int) override;
66  void DrawPolygon(float *, int) override;
67  void DrawColoredPolygon(float *points, int numPoints,
68  unsigned char *colors = nullptr,
69  int nc_comps = 0) override;
70  void DrawEllipseWedge(float x, float y, float outRx, float outRy,
71  float inRx, float inRy, float startAngle,
72  float stopAngle) override;
73  void DrawEllipticArc(float x, float y, float rX, float rY,
74  float startAngle, float stopAngle) override;
75  void DrawString(float *point, const vtkStdString &string) override;
76  void ComputeStringBounds(const vtkStdString &string,
77  float bounds[4]) override;
78  void DrawString(float *point, const vtkUnicodeString &string) override;
79  void ComputeStringBounds(const vtkUnicodeString &string,
80  float bounds[4]) override;
81  void ComputeJustifiedStringBounds(const char* string,
82  float bounds[4]) override;
83  void DrawMathTextString(float *point, const vtkStdString &str) override;
84  void DrawImage(float p[2], float scale, vtkImageData *image) override;
85  void DrawImage(const vtkRectf& pos, vtkImageData *image) override;
86  void SetColor4(unsigned char color[4]) override;
87  void SetTexture(vtkImageData* image, int properties) override;
88  void SetPointSize(float size) override;
89  void SetLineWidth(float width) override;
90  void DrawPolyData(float p[2], float scale, vtkPolyData* polyData,
91  vtkUnsignedCharArray* colors, int scalarMode) override;
92 
93  void SetLineType(int type) override;
94  void SetMatrix(vtkMatrix3x3 *m) override;
95  void GetMatrix(vtkMatrix3x3 *m) override;
96  void MultiplyMatrix(vtkMatrix3x3 *m) override;
97  void PushMatrix() override;
98  void PopMatrix() override;
99  void SetClipping(int *x) override;
100  void EnableClipping(bool enable) override;
101 
102 protected:
104  ~vtkPDFContextDevice2D() override;
105 
106  void PushGraphicsState();
107  void PopGraphicsState();
108 
109  void ApplyPenState();
110  void ApplyStrokeColor(unsigned char *color, int numComps);
111  void ApplyLineWidth(float width);
112  void ApplyLineType(int type);
113  void Stroke();
114 
115  void ApplyPenStateAsFill();
116  void ApplyBrushState();
117  void ApplyTextPropertyState();
118  void ApplyFillColor(unsigned char *color, int numComps);
119  void ApplyFillAlpha(unsigned char alpha);
120  void Fill(bool stroke = false);
121  void FillEvenOdd(bool stroke = false);
122 
123  void BeginClipPathForTexture();
124  void RegisterTexturePoints(float *data, int numPoints);
125  void FillTexture();
126 
127  // converts input to RGB if needed. Call Delete() on the returned object when
128  // finished with it.
129  vtkImageData* PrepareImageData(vtkImageData *in);
130 
131  void DrawEllipticArcSegments(float x, float y, float rX, float rY,
132  float startAngle, float stopAngle,
133  bool startPath);
134  int GetNumberOfArcIterations(float rX, float rY,
135  float startAngle, float stopAngle);
136 
137  void DrawCrossMarkers(bool highlight, float *points, int n,
138  unsigned char *colors, int nc_comps);
139  void DrawPlusMarkers(bool highlight, float *points, int n,
140  unsigned char *colors, int nc_comps);
141  void DrawSquareMarkers(bool highlight, float *points, int n,
142  unsigned char *colors, int nc_comps);
143  void DrawCircleMarkers(bool highlight, float *points, int n,
144  unsigned char *colors, int nc_comps);
145  void DrawDiamondMarkers(bool highlight, float *points, int n,
146  unsigned char *colors, int nc_comps);
147 
148  void DrawPath(vtkPath *path, float x, float y);
149 
150  void ApplyTransform();
151 
152  // This is weird, but the pen width must not be affected by the transform's
153  // scaling factors. This function returns the unscaled x/y components of
154  // the pen width.
155  vtkVector2f GetUnscaledPenWidth();
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
vtkContextDevice2D::DrawMarkers
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.
vtkContextDevice2D::ComputeStringBounds
virtual void ComputeStringBounds(const vtkStdString &string, float bounds[4])=0
Compute the bounds of the supplied string.
vtkContextDevice2D::DrawQuadStrip
virtual void DrawQuadStrip(float *, int)
Draw a quad using the specified number of points.
Definition: vtkContextDevice2D.h:119
vtkContextDevice2D::New
static vtkContextDevice2D * New()
vtkContextDevice2D::PopMatrix
virtual void PopMatrix()=0
Pop the current matrix off of the stack.
vtkX3D::alpha
Definition: vtkX3D.h:250
vtkX3D::scale
Definition: vtkX3D.h:229
vtkContextDevice2D::DrawPolyData
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....
vtkX3D::type
Definition: vtkX3D.h:516
vtkContextDevice2D::DrawQuad
virtual void DrawQuad(float *, int)
Draw a quad using the specified number of points.
Definition: vtkContextDevice2D.h:114
vtkContextDevice2D::MultiplyMatrix
virtual void MultiplyMatrix(vtkMatrix3x3 *m)=0
Multiply the current model view matrix by the supplied one.
vtkX3D::data
Definition: vtkX3D.h:315
vtkX3D::image
Definition: vtkX3D.h:374
vtkContextDevice2D::SetMatrix
virtual void SetMatrix(vtkMatrix3x3 *m)=0
Set the model view matrix for the display.
vtkPath
concrete dataset representing a path defined by Bezier curves.
Definition: vtkPath.h:35
vtkContextDevice2D::DrawString
virtual void DrawString(float *point, const vtkStdString &string)=0
Draw some text to the screen.
vtkUnsignedCharArray
dynamic, self-adjusting array of unsigned char
Definition: vtkUnsignedCharArray.h:41
vtkPDFContextDevice2D::Matrix
vtkNew< vtkTransform > Matrix
Definition: vtkPDFContextDevice2D.h:176
vtkContextDevice2D::SetColor4
virtual void SetColor4(unsigned char color[4])=0
Set the color for the device using unsigned char of length 4, RGBA.
vtkPDFContextDevice2D::Renderer
vtkRenderer * Renderer
Definition: vtkPDFContextDevice2D.h:178
vtkTransform
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:60
vtkContextDevice2D::SetClipping
virtual void SetClipping(int *x)=0
Supply an int array of length 4 with x1, y1, width, height specifying clipping region for the device ...
vtkContextDevice2D::DrawColoredPolygon
virtual void DrawColoredPolygon(float *points, int numPoints, unsigned char *colors=nullptr, int nc_comps=0)
Draw a polygon using the specified number of points.
vtkContextDevice2D::PushMatrix
virtual void PushMatrix()=0
Push the current matrix onto the stack.
vtkMatrix3x3
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:36
vtkContextDevice2D::ComputeJustifiedStringBounds
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...
vtkContextDevice2D::DrawPolygon
virtual void DrawPolygon(float *p, int n)
Draw a polygon using the specified number of points.
Definition: vtkContextDevice2D.h:125
vtkContextDevice2D::DrawImage
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....
vtkX3D::color
Definition: vtkX3D.h:221
vtkX3D::points
Definition: vtkX3D.h:446
vtkX3D::point
Definition: vtkX3D.h:236
vtkContextDevice2D::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkContextDevice2D::DrawEllipticArc
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 ...
vtkContextDevice2D::SetLineType
virtual void SetLineType(int type)=0
Set the line type type (using anonymous enum in vtkPen).
vtkContextDevice2D::SetPointSize
virtual void SetPointSize(float size)=0
Set the point size for glyphs/sprites.
vtkImageData
topologically and geometrically regular array of data
Definition: vtkImageData.h:45
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkPDFContextDevice2D
vtkContextDevice2D implementation for use with vtkPDFExporter.
Definition: vtkPDFContextDevice2D.h:37
vtkUnicodeString
String class that stores Unicode text.
Definition: vtkUnicodeString.h:72
vtkX3D::size
Definition: vtkX3D.h:253
vtkNew< vtkTransform >
vtkContextDevice2D::DrawPointSprites
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.
vtkX3D::startAngle
Definition: vtkX3D.h:486
vtkContextDevice2D::DrawPoly
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.
vtkContextDevice2D::GetMatrix
virtual void GetMatrix(vtkMatrix3x3 *m)=0
Set the model view matrix for the display.
vtkContextDevice2D
Abstract class for drawing 2D primitives.
Definition: vtkContextDevice2D.h:53
vtkContextDevice2D::DrawLines
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...
vtkNew.h
vtkContextDevice2D::SetTexture
virtual void SetTexture(vtkImageData *image, int properties)=0
Set the texture for the device, it is used to fill the polygons.
vtkRenderer
abstract specification for renderers
Definition: vtkRenderer.h:63
vtkColor3ub
Some derived classes for the different colors commonly used.
Definition: vtkColor.h:194
vtkContextDevice2D::DrawMathTextString
virtual void DrawMathTextString(float *point, const vtkStdString &string)=0
Draw text using MathText markup for mathematical equations.
vtkPolyData
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:85
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:40
vtkContextDevice2D::DrawEllipseWedge
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,...
vtkContextDevice2D::SetLineWidth
virtual void SetLineWidth(float width)=0
Set the line width.
vtkPDFContextDevice2D::PointSize
float PointSize
Definition: vtkPDFContextDevice2D.h:179
vtkRectf
Definition: vtkRect.h:332
vtkPDFContextDevice2D::Impl
Details * Impl
Definition: vtkPDFContextDevice2D.h:172
vtkContextDevice2D::EnableClipping
virtual void EnableClipping(bool enable)=0
Enable or disable the clipping of the scene.
vtkVector2f
Definition: vtkVector.h:418
vtkPDFContextDevice2D::IsInTexturedFill
bool IsInTexturedFill
Definition: vtkPDFContextDevice2D.h:182
vtkContextDevice2D::DrawPoints
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.
vtkContextDevice2D.h