VTK  9.0.1
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 class vtkColor3ub;
33 class vtkPath;
34 class vtkRenderer;
35 class vtkTransform;
36 
37 class VTKIOEXPORTPDF_EXPORT vtkPDFContextDevice2D : public vtkContextDevice2D
38 {
39 public:
42  void PrintSelf(ostream& os, vtkIndent indent) override;
43 
49  void SetHaruObjects(void* doc, void* page);
50 
52 
53  void DrawPoly(float* points, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
54  void DrawLines(float* f, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
55  void DrawPoints(float* points, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
56  void DrawPointSprites(vtkImageData* sprite, float* points, int n, unsigned char* colors = nullptr,
57  int nc_comps = 0) override;
58  void DrawMarkers(int shape, bool highlight, float* points, int n, unsigned char* colors = nullptr,
59  int nc_comps = 0) override;
60  void DrawQuad(float*, int) override;
61  void DrawQuadStrip(float*, int) override;
62  void DrawPolygon(float*, int) override;
64  float* points, int numPoints, unsigned char* colors = nullptr, int nc_comps = 0) override;
65  void DrawEllipseWedge(float x, float y, float outRx, float outRy, float inRx, float inRy,
66  float startAngle, float stopAngle) override;
68  float x, float y, float rX, float rY, float startAngle, float stopAngle) override;
69  void DrawString(float* point, const vtkStdString& string) override;
70  void ComputeStringBounds(const vtkStdString& string, float bounds[4]) override;
71  void DrawString(float* point, const vtkUnicodeString& string) override;
72  void ComputeStringBounds(const vtkUnicodeString& string, float bounds[4]) override;
73  void ComputeJustifiedStringBounds(const char* string, float bounds[4]) override;
74  void DrawMathTextString(float* point, const vtkStdString& str) override;
75  void DrawImage(float p[2], float scale, vtkImageData* image) override;
76  void DrawImage(const vtkRectf& pos, vtkImageData* image) override;
77  void SetColor4(unsigned char color[4]) override;
78  void SetTexture(vtkImageData* image, int properties) override;
79  void SetPointSize(float size) override;
80  void SetLineWidth(float width) override;
81  void DrawPolyData(float p[2], float scale, vtkPolyData* polyData, vtkUnsignedCharArray* colors,
82  int scalarMode) override;
83 
84  void SetLineType(int type) override;
85  void SetMatrix(vtkMatrix3x3* m) override;
86  void GetMatrix(vtkMatrix3x3* m) override;
87  void MultiplyMatrix(vtkMatrix3x3* m) override;
88  void PushMatrix() override;
89  void PopMatrix() override;
90  void SetClipping(int* x) override;
91  void EnableClipping(bool enable) override;
92 
93 protected:
96 
99 
101  void ApplyStrokeColor(unsigned char* color, int numComps);
102  void ApplyLineWidth(float width);
103  void ApplyLineType(int type);
104  void Stroke();
105 
109  void ApplyFillColor(unsigned char* color, int numComps);
110  void ApplyFillAlpha(unsigned char alpha);
111  void Fill(bool stroke = false);
112  void FillEvenOdd(bool stroke = false);
113 
115  void RegisterTexturePoints(float* data, int numPoints);
116  void FillTexture();
117 
118  // converts input to RGB if needed. Call Delete() on the returned object when
119  // finished with it.
121 
123  float x, float y, float rX, float rY, float startAngle, float stopAngle, bool startPath);
124  int GetNumberOfArcIterations(float rX, float rY, float startAngle, float stopAngle);
125 
126  void DrawCrossMarkers(bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
127  void DrawPlusMarkers(bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
128  void DrawSquareMarkers(bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
129  void DrawCircleMarkers(bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
131  bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
132 
133  void DrawPath(vtkPath* path, float x, float y);
134 
136 
137  // This is weird, but the pen width must not be affected by the transform's
138  // scaling factors. This function returns the unscaled x/y components of
139  // the pen width.
141 
142  // Converts a 2D transform matrix into a 3D transform matrix, or vice versa
143  static void Matrix3ToMatrix4(vtkMatrix3x3* mat3, double mat4[16]);
144  static void Matrix4ToMatrix3(double mat4[16], vtkMatrix3x3* mat3);
145  static void Matrix4ToMatrix3(double mat4[16], double mat3[9]);
146 
147  // Convert a 3D transform matrix to an HPDF transformation.
148  // trans = {a, b, c, d, x, y}, which define the transform:
149  // | a b x |
150  // | c d y |
151  // | 0 0 1 |
152  static void Matrix4ToHPDFTransform(const double mat4[16], float hpdfMat[6]);
153  static void Matrix3ToHPDFTransform(const double mat4[9], float hpdfMat[6]);
155  float a, float b, float c, float d, float x, float y, double mat3[9]);
156 
157  struct Details;
158  Details* Impl;
159 
160  // This is a 3D transform, the 2D version doesn't support push/pop.
162 
164  float PointSize;
165  float ClipBox[4]; // x, y, w, h
166 
168  float TextureBounds[4]; // xmin, xmax, ymin, ymax; used for placing textures
169 
170 private:
172  void operator=(const vtkPDFContextDevice2D&) = delete;
173 };
174 
175 #endif // vtkPDFContextDevice2D_h
vtkPDFContextDevice2D::FillTexture
void FillTexture()
vtkPDFContextDevice2D::Matrix4ToHPDFTransform
static void Matrix4ToHPDFTransform(const double mat4[16], float hpdfMat[6])
vtkPDFContextDevice2D::DrawMathTextString
void DrawMathTextString(float *point, const vtkStdString &str) override
Draw text using MathText markup for mathematical equations.
vtkPDFContextDevice2D::DrawPlusMarkers
void DrawPlusMarkers(bool highlight, float *points, int n, unsigned char *colors, int nc_comps)
vtkPDFContextDevice2D::New
static vtkPDFContextDevice2D * New()
vtkPDFContextDevice2D::PrepareImageData
vtkImageData * PrepareImageData(vtkImageData *in)
vtkPDFContextDevice2D::DrawPolygon
void DrawPolygon(float *, int) override
Draw a polygon using the specified number of points.
vtkX3D::alpha
@ alpha
Definition: vtkX3D.h:256
vtkX3D::scale
@ scale
Definition: vtkX3D.h:235
vtkPDFContextDevice2D::EnableClipping
void EnableClipping(bool enable) override
Enable or disable the clipping of the scene.
vtkPDFContextDevice2D::PushGraphicsState
void PushGraphicsState()
vtkPDFContextDevice2D::SetColor4
void SetColor4(unsigned char color[4]) override
Set the color for the device using unsigned char of length 4, RGBA.
vtkX3D::type
@ type
Definition: vtkX3D.h:522
vtkPDFContextDevice2D::SetPointSize
void SetPointSize(float size) override
Set the point size for glyphs/sprites.
vtkPDFContextDevice2D::DrawCircleMarkers
void DrawCircleMarkers(bool highlight, float *points, int n, unsigned char *colors, int nc_comps)
vtkPDFContextDevice2D::DrawDiamondMarkers
void DrawDiamondMarkers(bool highlight, float *points, int n, unsigned char *colors, int nc_comps)
vtkX3D::data
@ data
Definition: vtkX3D.h:321
vtkPDFContextDevice2D::DrawString
void DrawString(float *point, const vtkUnicodeString &string) override
Draw some text to the screen.
vtkPDFContextDevice2D::SetRenderer
void SetRenderer(vtkRenderer *)
vtkPDFContextDevice2D::~vtkPDFContextDevice2D
~vtkPDFContextDevice2D() override
vtkPDFContextDevice2D::SetLineType
void SetLineType(int type) override
Set the line type type (using anonymous enum in vtkPen).
vtkX3D::image
@ image
Definition: vtkX3D.h:380
vtkPDFContextDevice2D::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkPath
concrete dataset representing a path defined by Bezier curves.
Definition: vtkPath.h:33
vtkUnsignedCharArray
dynamic, self-adjusting array of unsigned char
Definition: vtkUnsignedCharArray.h:36
vtkPDFContextDevice2D::Matrix
vtkNew< vtkTransform > Matrix
Definition: vtkPDFContextDevice2D.h:161
vtkPDFContextDevice2D::DrawImage
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....
vtkPDFContextDevice2D::DrawLines
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...
vtkPDFContextDevice2D::ApplyLineWidth
void ApplyLineWidth(float width)
vtkPDFContextDevice2D::DrawPoints
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.
vtkPDFContextDevice2D::PushMatrix
void PushMatrix() override
Push the current matrix onto the stack.
vtkPDFContextDevice2D::DrawQuad
void DrawQuad(float *, int) override
Draw a quad using the specified number of points.
vtkPDFContextDevice2D::ApplyLineType
void ApplyLineType(int type)
vtkPDFContextDevice2D::Matrix4ToMatrix3
static void Matrix4ToMatrix3(double mat4[16], vtkMatrix3x3 *mat3)
vtkPDFContextDevice2D::Renderer
vtkRenderer * Renderer
Definition: vtkPDFContextDevice2D.h:163
vtkPDFContextDevice2D::DrawPoly
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.
vtkTransform
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:55
vtkMatrix3x3
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:34
vtkPDFContextDevice2D::GetNumberOfArcIterations
int GetNumberOfArcIterations(float rX, float rY, float startAngle, float stopAngle)
vtkPDFContextDevice2D::MultiplyMatrix
void MultiplyMatrix(vtkMatrix3x3 *m) override
Multiply the current model view matrix by the supplied one.
vtkPDFContextDevice2D::ApplyBrushState
void ApplyBrushState()
vtkPDFContextDevice2D::SetHaruObjects
void SetHaruObjects(void *doc, void *page)
Set the HPDF_Doc and HPDF_Page to use while exporting the scene.
vtkPDFContextDevice2D::ApplyTextPropertyState
void ApplyTextPropertyState()
vtkX3D::color
@ color
Definition: vtkX3D.h:227
vtkX3D::points
@ points
Definition: vtkX3D.h:452
vtkPDFContextDevice2D::DrawPolyData
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....
vtkX3D::point
@ point
Definition: vtkX3D.h:242
vtkPDFContextDevice2D::DrawEllipticArc
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 ...
vtkPDFContextDevice2D::Fill
void Fill(bool stroke=false)
vtkPDFContextDevice2D::DrawMarkers
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.
vtkPDFContextDevice2D::SetTexture
void SetTexture(vtkImageData *image, int properties) override
Set the texture for the device, it is used to fill the polygons.
vtkPDFContextDevice2D::ApplyPenStateAsFill
void ApplyPenStateAsFill()
vtkPDFContextDevice2D::BeginClipPathForTexture
void BeginClipPathForTexture()
vtkPDFContextDevice2D::PopGraphicsState
void PopGraphicsState()
vtkImageData
topologically and geometrically regular array of data
Definition: vtkImageData.h:42
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:34
vtkPDFContextDevice2D
vtkContextDevice2D implementation for use with vtkPDFExporter.
Definition: vtkPDFContextDevice2D.h:38
vtkUnicodeString
String class that stores Unicode text.
Definition: vtkUnicodeString.h:70
vtkPDFContextDevice2D::SetMatrix
void SetMatrix(vtkMatrix3x3 *m) override
Set the model view matrix for the display.
vtkX3D::size
@ size
Definition: vtkX3D.h:259
vtkNew< vtkTransform >
vtkPDFContextDevice2D::ApplyPenState
void ApplyPenState()
vtkPDFContextDevice2D::HPDFTransformToMatrix3
static void HPDFTransformToMatrix3(float a, float b, float c, float d, float x, float y, double mat3[9])
vtkX3D::startAngle
@ startAngle
Definition: vtkX3D.h:492
vtkPDFContextDevice2D::ApplyFillAlpha
void ApplyFillAlpha(unsigned char alpha)
vtkPDFContextDevice2D::DrawImage
void DrawImage(const vtkRectf &pos, vtkImageData *image) override
Draw the supplied image at the given position.
vtkPDFContextDevice2D::SetLineWidth
void SetLineWidth(float width) override
Set the line width.
vtkPDFContextDevice2D::Stroke
void Stroke()
vtkContextDevice2D
Abstract class for drawing 2D primitives.
Definition: vtkContextDevice2D.h:51
vtkPDFContextDevice2D::vtkPDFContextDevice2D
vtkPDFContextDevice2D()
vtkPDFContextDevice2D::DrawQuadStrip
void DrawQuadStrip(float *, int) override
Draw a quad using the specified number of points.
vtkPDFContextDevice2D::ApplyStrokeColor
void ApplyStrokeColor(unsigned char *color, int numComps)
vtkPDFContextDevice2D::ComputeStringBounds
void ComputeStringBounds(const vtkStdString &string, float bounds[4]) override
Compute the bounds of the supplied string.
vtkPDFContextDevice2D::ComputeStringBounds
void ComputeStringBounds(const vtkUnicodeString &string, float bounds[4]) override
Compute the bounds of the supplied string.
vtkPDFContextDevice2D::Matrix3ToMatrix4
static void Matrix3ToMatrix4(vtkMatrix3x3 *mat3, double mat4[16])
vtkPDFContextDevice2D::ApplyTransform
void ApplyTransform()
vtkNew.h
vtkPDFContextDevice2D::ComputeJustifiedStringBounds
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...
vtkRenderer
abstract specification for renderers
Definition: vtkRenderer.h:59
vtkPDFContextDevice2D::DrawCrossMarkers
void DrawCrossMarkers(bool highlight, float *points, int n, unsigned char *colors, int nc_comps)
vtkColor3ub
Some derived classes for the different colors commonly used.
Definition: vtkColor.h:195
vtkPolyData
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:85
vtkPDFContextDevice2D::DrawPointSprites
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.
vtkPDFContextDevice2D::RegisterTexturePoints
void RegisterTexturePoints(float *data, int numPoints)
vtkPDFContextDevice2D::DrawPath
void DrawPath(vtkPath *path, float x, float y)
vtkPDFContextDevice2D::GetMatrix
void GetMatrix(vtkMatrix3x3 *m) override
Set the model view matrix for the display.
vtkPDFContextDevice2D::ApplyFillColor
void ApplyFillColor(unsigned char *color, int numComps)
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:35
vtkPDFContextDevice2D::GetUnscaledPenWidth
vtkVector2f GetUnscaledPenWidth()
vtkPDFContextDevice2D::Matrix4ToMatrix3
static void Matrix4ToMatrix3(double mat4[16], double mat3[9])
vtkPDFContextDevice2D::SetClipping
void SetClipping(int *x) override
Supply an int array of length 4 with x1, y1, width, height specifying clipping region for the device ...
vtkPDFContextDevice2D::DrawColoredPolygon
void DrawColoredPolygon(float *points, int numPoints, unsigned char *colors=nullptr, int nc_comps=0) override
Draw a polygon using the specified number of points.
vtkPDFContextDevice2D::DrawEllipseWedge
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,...
vtkPDFContextDevice2D::PointSize
float PointSize
Definition: vtkPDFContextDevice2D.h:164
vtkRectf
Definition: vtkRect.h:327
vtkPDFContextDevice2D::DrawEllipticArcSegments
void DrawEllipticArcSegments(float x, float y, float rX, float rY, float startAngle, float stopAngle, bool startPath)
vtkPDFContextDevice2D::Impl
Details * Impl
Definition: vtkPDFContextDevice2D.h:157
vtkPDFContextDevice2D::DrawSquareMarkers
void DrawSquareMarkers(bool highlight, float *points, int n, unsigned char *colors, int nc_comps)
vtkPDFContextDevice2D::Matrix3ToHPDFTransform
static void Matrix3ToHPDFTransform(const double mat4[9], float hpdfMat[6])
vtkVector2f
Definition: vtkVector.h:433
vtkPDFContextDevice2D::IsInTexturedFill
bool IsInTexturedFill
Definition: vtkPDFContextDevice2D.h:167
vtkPDFContextDevice2D::DrawString
void DrawString(float *point, const vtkStdString &string) override
Draw some text to the screen.
vtkPDFContextDevice2D::FillEvenOdd
void FillEvenOdd(bool stroke=false)
vtkContextDevice2D.h
vtkPDFContextDevice2D::PopMatrix
void PopMatrix() override
Pop the current matrix off of the stack.