VTK  9.3.20240327
vtkPDFContextDevice2D.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
13 #ifndef vtkPDFContextDevice2D_h
14 #define vtkPDFContextDevice2D_h
15 
16 #include "vtkContextDevice2D.h"
17 #include "vtkIOExportPDFModule.h" // For export macro
18 #include "vtkNew.h" // For vtkNew!
19 
20 VTK_ABI_NAMESPACE_BEGIN
21 class vtkColor3ub;
22 class vtkPath;
23 class vtkRenderer;
24 class vtkTransform;
25 
26 class VTKIOEXPORTPDF_EXPORT vtkPDFContextDevice2D : public vtkContextDevice2D
27 {
28 public:
31  void PrintSelf(ostream& os, vtkIndent indent) override;
32 
38  void SetHaruObjects(void* doc, void* page);
39 
41 
42  void DrawPoly(float* points, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
43  void DrawLines(float* f, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
44  void DrawPoints(float* points, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
45  void DrawPointSprites(vtkImageData* sprite, float* points, int n, unsigned char* colors = nullptr,
46  int nc_comps = 0) override;
47  void DrawMarkers(int shape, bool highlight, float* points, int n, unsigned char* colors = nullptr,
48  int nc_comps = 0) override;
49  void DrawQuad(float*, int) override;
50  void DrawQuadStrip(float*, int) override;
51  void DrawPolygon(float*, int) override;
53  float* points, int numPoints, unsigned char* colors = nullptr, int nc_comps = 0) override;
54  void DrawEllipseWedge(float x, float y, float outRx, float outRy, float inRx, float inRy,
55  float startAngle, float stopAngle) override;
57  float x, float y, float rX, float rY, float startAngle, float stopAngle) override;
58  void DrawString(float* point, const vtkStdString& string) override;
59  void ComputeStringBounds(const vtkStdString& string, float bounds[4]) override;
60  void ComputeJustifiedStringBounds(const char* string, float bounds[4]) override;
61  void DrawMathTextString(float* point, const vtkStdString& str) override;
62  void DrawImage(float p[2], float scale, vtkImageData* image) override;
63  void DrawImage(const vtkRectf& pos, vtkImageData* image) override;
64  void SetColor4(unsigned char color[4]) override;
65  void SetTexture(vtkImageData* image, int properties) override;
66  void SetPointSize(float size) override;
67  void SetLineWidth(float width) override;
68  void DrawPolyData(float p[2], float scale, vtkPolyData* polyData, vtkUnsignedCharArray* colors,
69  int scalarMode) override;
70 
71  void SetLineType(int type) override;
72  void SetMatrix(vtkMatrix3x3* m) override;
73  void GetMatrix(vtkMatrix3x3* m) override;
74  void MultiplyMatrix(vtkMatrix3x3* m) override;
75  void PushMatrix() override;
76  void PopMatrix() override;
77  void SetClipping(int* x) override;
78  void EnableClipping(bool enable) override;
79 
80 protected:
83 
86 
87  void ApplyPenState();
88  void ApplyStrokeColor(unsigned char* color, int numComps);
89  void ApplyLineWidth(float width);
90  void ApplyLineType(int type);
91  void Stroke();
92 
96  void ApplyFillColor(unsigned char* color, int numComps);
97  void ApplyFillAlpha(unsigned char alpha);
98  void Fill(bool stroke = false);
99  void FillEvenOdd(bool stroke = false);
100 
102  void RegisterTexturePoints(float* data, int numPoints);
103  void FillTexture();
104 
105  // converts input to RGB if needed. Call Delete() on the returned object when
106  // finished with it.
108 
110  float x, float y, float rX, float rY, float startAngle, float stopAngle, bool startPath);
111  int GetNumberOfArcIterations(float rX, float rY, float startAngle, float stopAngle);
112 
113  void DrawCrossMarkers(bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
114  void DrawPlusMarkers(bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
115  void DrawSquareMarkers(bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
116  void DrawCircleMarkers(bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
118  bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
119 
120  void DrawPath(vtkPath* path, float x, float y);
121 
123 
124  // This is weird, but the pen width must not be affected by the transform's
125  // scaling factors. This function returns the unscaled x/y components of
126  // the pen width.
128 
129  // Converts a 2D transform matrix into a 3D transform matrix, or vice versa
130  static void Matrix3ToMatrix4(vtkMatrix3x3* mat3, double mat4[16]);
131  static void Matrix4ToMatrix3(double mat4[16], vtkMatrix3x3* mat3);
132  static void Matrix4ToMatrix3(double mat4[16], double mat3[9]);
133 
134  // Convert a 3D transform matrix to an HPDF transformation.
135  // trans = {a, b, c, d, x, y}, which define the transform:
136  // | a b x |
137  // | c d y |
138  // | 0 0 1 |
139  static void Matrix4ToHPDFTransform(const double mat4[16], float hpdfMat[6]);
140  static void Matrix3ToHPDFTransform(const double mat3[9], float hpdfMat[6]);
142  float a, float b, float c, float d, float x, float y, double mat3[9]);
143 
144  struct Details;
145  Details* Impl;
146 
147  // This is a 3D transform, the 2D version doesn't support push/pop.
149 
151  float PointSize;
152  float ClipBox[4]; // x, y, w, h
153 
155  float TextureBounds[4]; // xmin, xmax, ymin, ymax; used for placing textures
156 
157 private:
159  void operator=(const vtkPDFContextDevice2D&) = delete;
160 };
161 
162 VTK_ABI_NAMESPACE_END
163 #endif // vtkPDFContextDevice2D_h
Some derived classes for the different colors commonly used.
Definition: vtkColor.h:203
Abstract class for drawing 2D primitives.
topologically and geometrically regular array of data
Definition: vtkImageData.h:155
a simple class to control print indentation
Definition: vtkIndent.h:108
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:55
vtkContextDevice2D implementation for use with vtkPDFExporter.
void DrawEllipticArcSegments(float x, float y, float rX, float rY, float startAngle, float stopAngle, bool startPath)
void DrawQuadStrip(float *, int) override
Draw a quad using the specified number of points.
void DrawSquareMarkers(bool highlight, float *points, int n, unsigned char *colors, int nc_comps)
void Fill(bool stroke=false)
static void HPDFTransformToMatrix3(float a, float b, float c, float d, float x, float y, double mat3[9])
void DrawPolyData(float p[2], float scale, vtkPolyData *polyData, vtkUnsignedCharArray *colors, int scalarMode) override
Draw the supplied PolyData at the given x, y (p[0], p[1]) (bottom corner), scaled by scale (1....
int GetNumberOfArcIterations(float rX, float rY, float startAngle, float stopAngle)
void DrawEllipticArc(float x, float y, float rX, float rY, float startAngle, float stopAngle) override
Draw an elliptic arc with center at x,y with radii rX and rY between angles startAngle and stopAngle ...
void ApplyLineType(int type)
void ApplyFillColor(unsigned char *color, int numComps)
static void Matrix4ToMatrix3(double mat4[16], vtkMatrix3x3 *mat3)
void SetRenderer(vtkRenderer *)
vtkNew< vtkTransform > Matrix
void DrawMathTextString(float *point, const vtkStdString &str) override
Draw text using MathText markup for mathematical equations.
void SetLineType(int type) override
Set the line type type (using anonymous enum in vtkPen).
void PushMatrix() override
Push the current matrix onto the stack.
void DrawImage(const vtkRectf &pos, vtkImageData *image) override
Draw the supplied image at the given position.
static vtkPDFContextDevice2D * New()
void FillEvenOdd(bool stroke=false)
void ApplyLineWidth(float width)
void SetLineWidth(float width) override
Set the line width.
void DrawColoredPolygon(float *points, int numPoints, unsigned char *colors=nullptr, int nc_comps=0) override
Draw a polygon using the specified number of points.
static void Matrix3ToMatrix4(vtkMatrix3x3 *mat3, double mat4[16])
~vtkPDFContextDevice2D() override
void DrawPoints(float *points, int n, unsigned char *colors=nullptr, int nc_comps=0) override
Draw a series of points - fastest code path due to memory layout of the coordinates.
void EnableClipping(bool enable) override
Enable or disable the clipping of the scene.
void DrawMarkers(int shape, bool highlight, float *points, int n, unsigned char *colors=nullptr, int nc_comps=0) override
Draw a series of markers centered at the points supplied.
void GetMatrix(vtkMatrix3x3 *m) override
Set the model view matrix for the display.
void ComputeStringBounds(const vtkStdString &string, float bounds[4]) override
Compute the bounds of the supplied string.
static void Matrix4ToMatrix3(double mat4[16], double mat3[9])
void DrawQuad(float *, int) override
Draw a quad using the specified number of points.
void SetHaruObjects(void *doc, void *page)
Set the HPDF_Doc and HPDF_Page to use while exporting the scene.
vtkImageData * PrepareImageData(vtkImageData *in)
void DrawImage(float p[2], float scale, vtkImageData *image) override
Draw the supplied image at the given x, y (p[0], p[1]) (bottom corner), scaled by scale (1....
void DrawPolygon(float *, int) override
Draw a polygon using the specified number of points.
void SetColor4(unsigned char color[4]) override
Set the color for the device using unsigned char of length 4, RGBA.
void ApplyFillAlpha(unsigned char alpha)
vtkVector2f GetUnscaledPenWidth()
void DrawString(float *point, const vtkStdString &string) override
Draw some text to the screen.
void MultiplyMatrix(vtkMatrix3x3 *m) override
Multiply the current model view matrix by the supplied one.
void ApplyStrokeColor(unsigned char *color, int numComps)
static void Matrix3ToHPDFTransform(const double mat3[9], float hpdfMat[6])
void DrawPointSprites(vtkImageData *sprite, float *points, int n, unsigned char *colors=nullptr, int nc_comps=0) override
Draw a series of point sprites, images centred at the points supplied.
static void Matrix4ToHPDFTransform(const double mat4[16], float hpdfMat[6])
void PopMatrix() override
Pop the current matrix off of the stack.
void DrawPlusMarkers(bool highlight, float *points, int n, unsigned char *colors, int nc_comps)
void SetPointSize(float size) override
Set the point size for glyphs/sprites.
void DrawPath(vtkPath *path, float x, float y)
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetClipping(int *x) override
Supply an int array of length 4 with x1, y1, width, height specifying clipping region for the device ...
void DrawLines(float *f, int n, unsigned char *colors=nullptr, int nc_comps=0) override
Draw lines using the points - memory layout is as follows: l1p1,l1p2,l2p1,l2p2...
void SetTexture(vtkImageData *image, int properties) override
Set the texture for the device, it is used to fill the polygons.
void DrawCrossMarkers(bool highlight, float *points, int n, unsigned char *colors, int nc_comps)
void DrawDiamondMarkers(bool highlight, float *points, int n, unsigned char *colors, int nc_comps)
void DrawPoly(float *points, int n, unsigned char *colors=nullptr, int nc_comps=0) override
Draw a poly line using the points - fastest code path due to memory layout of the coordinates.
void DrawCircleMarkers(bool highlight, float *points, int n, unsigned char *colors, int nc_comps)
void SetMatrix(vtkMatrix3x3 *m) override
Set the model view matrix for the display.
void DrawEllipseWedge(float x, float y, float outRx, float outRy, float inRx, float inRy, float startAngle, float stopAngle) override
Draw an elliptic wedge with center at x, y, outer radii outRx, outRy, inner radii inRx,...
void RegisterTexturePoints(float *data, int numPoints)
void ComputeJustifiedStringBounds(const char *string, float bounds[4]) override
Compute the bounds of the supplied string while taking into account the justification of the currentl...
concrete dataset representing a path defined by Bezier curves.
Definition: vtkPath.h:44
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:180
abstract specification for renderers
Definition: vtkRenderer.h:171
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:78
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:159
dynamic, self-adjusting array of unsigned char
@ point
Definition: vtkX3D.h:236
@ points
Definition: vtkX3D.h:446
@ startAngle
Definition: vtkX3D.h:486
@ scale
Definition: vtkX3D.h:229
@ type
Definition: vtkX3D.h:516
@ alpha
Definition: vtkX3D.h:250
@ color
Definition: vtkX3D.h:221
@ image
Definition: vtkX3D.h:374
@ size
Definition: vtkX3D.h:253
@ data
Definition: vtkX3D.h:315