1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkGL2PSUtilities.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 =========================================================================*/
15 // .NAME vtkGL2PSUtilities - Helper functions for using GL2PS within VTK
16 // .SECTION Description
17 // vtkGL2PSUtilities implements some static helper function that simplify
18 // calling GL2PS routines on VTK objects. This class is meant for internal use
19 // only and is subject to change.
20 
21 #ifndef vtkGL2PSUtilities_h
22 #define vtkGL2PSUtilities_h
23 
24 #include "vtkObject.h"
25 #include "vtkRenderingGL2PSModule.h" // For export macro
26 
27 class vtkImageData;
28 class vtkMatrix4x4;
29 class vtkPath;
30 class vtkPoints;
31 class vtkRenderWindow;
32 class vtkTextProperty;
33 
34 class VTKRENDERINGGL2PS_EXPORT vtkGL2PSUtilities : public vtkObject
35 {
36 public:
37   static vtkGL2PSUtilities *New();
vtkTypeMacro(vtkGL2PSUtilities,vtkObject)38   vtkTypeMacro(vtkGL2PSUtilities, vtkObject)
39   void PrintSelf(ostream& os, vtkIndent indent)
40   {
41     this->Superclass::PrintSelf(os, indent);
42   }
43 
44   // Description:
45   // Format the text in str according to tprop and instruct GL2PS to draw it at
46   // world coordinate pos. Background depth is the z value for the background
47   // quad, and should be in NDC space.
48   static void DrawString(const char *str, vtkTextProperty *tprop, double pos[3],
49                          double backgroundDepth);
50 
51   // Description:
52   // Translate the tprop's fontname into a Postscript font name.
53   static const char * TextPropertyToPSFontName(vtkTextProperty *tprop);
54 
55   // Description:
56   // Convert the alignment hint in tprop to a GL2PS text alignment constant.
57   static int TextPropertyToGL2PSAlignment(vtkTextProperty *tprop);
58 
59   // Description:
60   // Get the current RenderWindow that is being exported
GetRenderWindow()61   static vtkRenderWindow *GetRenderWindow()
62   {
63     return vtkGL2PSUtilities::RenderWindow;
64   }
65 
66   // Description:
67   // Transform the path using the actor's matrix and current GL state, then
68   // draw it to GL2PS. The label string is inserted into the GL2PS output at the
69   // beginning of the path specification as a comment on supported backends.
70   static void Draw3DPath(vtkPath *path, vtkMatrix4x4 *actorMatrix,
71                          double rasterPos[3], unsigned char actorColor[4],
72                          const char *label = NULL);
73   // Description:
74   // Generate PS, EPS, or SVG markup from a vtkPath object, and then inject it
75   // into the output using the gl2psSpecial command. The path is translated
76   // uniformly in the scene by windowPos. It is scaled by scale and rotated
77   // counter-clockwise by rotateAngle. The rasterPos is in world coordinates
78   // and determines clipping and depth. If scale is NULL, no scaling is done.
79   // If strokeWidth is positive, the path will be stroked with the indicated
80   // width. If zero or negative, the path will be filled (default).
81   // The label string is inserted into the GL2PS output at the beginning of the
82   // path specification as a comment on supported backends.
83   static void DrawPath(vtkPath *path, double rasterPos[3], double windowPos[2],
84                        unsigned char rgba[4], double scale[2] = NULL,
85                        double rotateAngle = 0.0, float strokeWidth = -1,
86                        const char *label = NULL);
87 
88   // Description:
89   // Get whether all text will be exported as paths.
GetTextAsPath()90   static bool GetTextAsPath()
91   {
92     return vtkGL2PSUtilities::TextAsPath;
93   }
94 
95   // Description:
96   // Get a scaling factor for the point size or line width used by GL2PS.
97   // Default value: 5/7.
GetPointSizeFactor()98   static float GetPointSizeFactor()
99     { return vtkGL2PSUtilities::PointSizeFactor; }
GetLineWidthFactor()100   static float GetLineWidthFactor()
101     { return vtkGL2PSUtilities::LineWidthFactor; }
102 
103 protected:
104   friend class vtkGL2PSExporter;
105 
106   static void StartExport();
107   static void FinishExport();
108 
SetPointSizeFactor(float f)109   static void SetPointSizeFactor(float f)
110     { vtkGL2PSUtilities::PointSizeFactor = f; }
111 
SetLineWidthFactor(float f)112   static void SetLineWidthFactor(float f)
113     { vtkGL2PSUtilities::LineWidthFactor = f; }
114 
SetTextAsPath(bool b)115   static void SetTextAsPath(bool b)
116   {
117     vtkGL2PSUtilities::TextAsPath = b;
118   }
119 
SetRenderWindow(vtkRenderWindow * renWin)120   static void SetRenderWindow(vtkRenderWindow *renWin)
121   {
122     vtkGL2PSUtilities::RenderWindow = renWin;
123   }
124 
125   static void DrawPathPS(vtkPath *path, double rasterPos[3],
126                          double windowPos[2], unsigned char rgba[4],
127                          double scale[2] = NULL, double rotateAngle = 0.0,
128                          float strokeWidth = -1, const char *label = NULL);
129   static void DrawPathPDF(vtkPath *path, double rasterPos[3],
130                           double windowPos[2], unsigned char rgba[4],
131                           double scale[2] = NULL, double rotateAngle = 0.0,
132                           float strokeWidth = -1, const char *label = NULL);
133   static void DrawPathSVG(vtkPath *path, double rasterPos[3],
134                           double windowPos[2], unsigned char rgba[4],
135                           double scale[2] = NULL, double rotateAngle = 0.0,
136                           float strokeWidth = -1, const char *label = NULL);
137 
vtkGL2PSUtilities()138   vtkGL2PSUtilities() {}
~vtkGL2PSUtilities()139   ~vtkGL2PSUtilities() {}
140 
141 private:
142   vtkGL2PSUtilities(const vtkGL2PSUtilities &); // Not implemented
143   void operator=(const vtkGL2PSUtilities&); // Not implemented
144 
145   static vtkRenderWindow *RenderWindow;
146   static bool TextAsPath;
147   static float PointSizeFactor;
148   static float LineWidthFactor;
149 
150   // Description:
151   // Project the point from world coordinates into device coordinates.
152   static void ProjectPoint(double point[3], vtkMatrix4x4 *actorMatrix = NULL);
153   static void ProjectPoint(double point[4], vtkMatrix4x4 * transformMatrix,
154                            double viewportOrigin[2], double halfWidth,
155                            double halfHeight, double zfact1, double zfact2);
156   static void ProjectPoints(vtkPoints *points,
157                             vtkMatrix4x4 *actorMatrix = NULL);
158 
159   // Description:
160   // Unproject the point from device coordinates into world coordinates.
161   // Input Z coordinate should be in NDC space.
162   static void UnprojectPoint(double point[4], vtkMatrix4x4 *invTransformMatrix,
163                              double viewportOrigin[2], double halfWidth,
164                              double halfHeight, double zfact1, double zfact2);
165   static void UnprojectPoints(double *points3D, vtkIdType numPoints,
166                               vtkMatrix4x4 *actorMatrix = NULL);
167 };
168 
169 #endif
170