VTK  9.2.20221001
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 "vtkContextDevice2D.h"
29 #include "vtkIOExportPDFModule.h" // For export macro
30 #include "vtkNew.h" // For vtkNew!
31 
32 VTK_ABI_NAMESPACE_BEGIN
33 class vtkColor3ub;
34 class vtkPath;
35 class vtkRenderer;
36 class vtkTransform;
37 
38 class VTKIOEXPORTPDF_EXPORT vtkPDFContextDevice2D : public vtkContextDevice2D
39 {
40 public:
43  void PrintSelf(ostream& os, vtkIndent indent) override;
44 
50  void SetHaruObjects(void* doc, void* page);
51 
53 
54  void DrawPoly(float* points, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
55  void DrawLines(float* f, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
56  void DrawPoints(float* points, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
57  void DrawPointSprites(vtkImageData* sprite, float* points, int n, unsigned char* colors = nullptr,
58  int nc_comps = 0) override;
59  void DrawMarkers(int shape, bool highlight, float* points, int n, unsigned char* colors = nullptr,
60  int nc_comps = 0) override;
61  void DrawQuad(float*, int) override;
62  void DrawQuadStrip(float*, int) override;
63  void DrawPolygon(float*, int) override;
65  float* points, int numPoints, unsigned char* colors = nullptr, int nc_comps = 0) override;
66  void DrawEllipseWedge(float x, float y, float outRx, float outRy, float inRx, float inRy,
67  float startAngle, float stopAngle) override;
69  float x, float y, float rX, float rY, float startAngle, float stopAngle) override;
70  void DrawString(float* point, const vtkStdString& string) override;
71  void ComputeStringBounds(const vtkStdString& string, float bounds[4]) override;
72  void ComputeJustifiedStringBounds(const char* string, float bounds[4]) override;
73  void DrawMathTextString(float* point, const vtkStdString& str) override;
74  void DrawImage(float p[2], float scale, vtkImageData* image) override;
75  void DrawImage(const vtkRectf& pos, vtkImageData* image) override;
76  void SetColor4(unsigned char color[4]) override;
77  void SetTexture(vtkImageData* image, int properties) override;
78  void SetPointSize(float size) override;
79  void SetLineWidth(float width) override;
80  void DrawPolyData(float p[2], float scale, vtkPolyData* polyData, vtkUnsignedCharArray* colors,
81  int scalarMode) override;
82 
83  void SetLineType(int type) override;
84  void SetMatrix(vtkMatrix3x3* m) override;
85  void GetMatrix(vtkMatrix3x3* m) override;
86  void MultiplyMatrix(vtkMatrix3x3* m) override;
87  void PushMatrix() override;
88  void PopMatrix() override;
89  void SetClipping(int* x) override;
90  void EnableClipping(bool enable) override;
91 
92 protected:
95 
98 
99  void ApplyPenState();
100  void ApplyStrokeColor(unsigned char* color, int numComps);
101  void ApplyLineWidth(float width);
102  void ApplyLineType(int type);
103  void Stroke();
104 
108  void ApplyFillColor(unsigned char* color, int numComps);
109  void ApplyFillAlpha(unsigned char alpha);
110  void Fill(bool stroke = false);
111  void FillEvenOdd(bool stroke = false);
112 
114  void RegisterTexturePoints(float* data, int numPoints);
115  void FillTexture();
116 
117  // converts input to RGB if needed. Call Delete() on the returned object when
118  // finished with it.
120 
122  float x, float y, float rX, float rY, float startAngle, float stopAngle, bool startPath);
123  int GetNumberOfArcIterations(float rX, float rY, float startAngle, float stopAngle);
124 
125  void DrawCrossMarkers(bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
126  void DrawPlusMarkers(bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
127  void DrawSquareMarkers(bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
128  void DrawCircleMarkers(bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
130  bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
131 
132  void DrawPath(vtkPath* path, float x, float y);
133 
135 
136  // This is weird, but the pen width must not be affected by the transform's
137  // scaling factors. This function returns the unscaled x/y components of
138  // the pen width.
140 
141  // Converts a 2D transform matrix into a 3D transform matrix, or vice versa
142  static void Matrix3ToMatrix4(vtkMatrix3x3* mat3, double mat4[16]);
143  static void Matrix4ToMatrix3(double mat4[16], vtkMatrix3x3* mat3);
144  static void Matrix4ToMatrix3(double mat4[16], double mat3[9]);
145 
146  // Convert a 3D transform matrix to an HPDF transformation.
147  // trans = {a, b, c, d, x, y}, which define the transform:
148  // | a b x |
149  // | c d y |
150  // | 0 0 1 |
151  static void Matrix4ToHPDFTransform(const double mat4[16], float hpdfMat[6]);
152  static void Matrix3ToHPDFTransform(const double mat3[9], float hpdfMat[6]);
154  float a, float b, float c, float d, float x, float y, double mat3[9]);
155 
156  struct Details;
157  Details* Impl;
158 
159  // This is a 3D transform, the 2D version doesn't support push/pop.
161 
163  float PointSize;
164  float ClipBox[4]; // x, y, w, h
165 
167  float TextureBounds[4]; // xmin, xmax, ymin, ymax; used for placing textures
168 
169 private:
171  void operator=(const vtkPDFContextDevice2D&) = delete;
172 };
173 
174 VTK_ABI_NAMESPACE_END
175 #endif // vtkPDFContextDevice2D_h
Some derived classes for the different colors commonly used.
Definition: vtkColor.h:305
Abstract class for drawing 2D primitives.
topologically and geometrically regular array of data
Definition: vtkImageData.h:164
a simple class to control print indentation
Definition: vtkIndent.h:120
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:67
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:37
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:201
abstract specification for renderers
Definition: vtkRenderer.h:183
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:110
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:171
dynamic, self-adjusting array of unsigned char
@ point
Definition: vtkX3D.h:248
@ points
Definition: vtkX3D.h:458
@ startAngle
Definition: vtkX3D.h:498
@ scale
Definition: vtkX3D.h:241
@ type
Definition: vtkX3D.h:528
@ alpha
Definition: vtkX3D.h:262
@ color
Definition: vtkX3D.h:233
@ image
Definition: vtkX3D.h:386
@ size
Definition: vtkX3D.h:265
@ data
Definition: vtkX3D.h:327