1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkOpenGLGL2PSHelper.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 16 /** 17 * @class vtkOpenGLGL2PSHelper 18 * @brief Access GL2PS functionality. 19 * 20 * 21 * This class provides convenience functions that can be used to draw into a 22 * GL2PS context. Link to vtkRenderingGL2PSOpenGL2 to bring in the 23 * vtkOpenGLGL2PSHelperImpl class, the object factory override that implements 24 * this interface. 25 */ 26 27 #ifndef vtkOpenGLGL2PSHelper_h 28 #define vtkOpenGLGL2PSHelper_h 29 30 #include "vtkObject.h" 31 #include "vtkRenderingOpenGL2Module.h" // For export macro 32 #include <string> // For string usage 33 34 class vtkActor; 35 class vtkImageData; 36 class vtkMatrix4x4; 37 class vtkPath; 38 class vtkRenderer; 39 class vtkRenderWindow; 40 class vtkTextProperty; 41 class vtkTransformFeedback; 42 43 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLGL2PSHelper : public vtkObject 44 { 45 public: 46 static vtkOpenGLGL2PSHelper* New(); 47 vtkAbstractTypeMacro(vtkOpenGLGL2PSHelper, vtkObject); 48 void PrintSelf(ostream& os, vtkIndent indent) override; 49 50 ///@{ 51 /** 52 * The global instance. Only set during export. 53 */ 54 static vtkOpenGLGL2PSHelper* GetInstance(); 55 static void SetInstance(vtkOpenGLGL2PSHelper*); 56 ///@} 57 58 ///@{ 59 /** 60 * Get the renderwindow that's being exported. 61 */ 62 vtkGetMacro(RenderWindow, vtkRenderWindow*); 63 ///@} 64 65 enum State 66 { 67 Inactive = 0, //! No export active 68 Background, //! Rendering rasterized props for the background. 69 Capture //! Capturing vectorized objects. 70 }; 71 72 ///@{ 73 /** 74 * Get the current export state. Vector images are rendered in two passes: 75 * First, all non-vectorizable props are rendered, and the resulting image 76 * is inserted as a raster image into the background of the exported file 77 * (ActiveState == Background). Next, all vectorizable props are drawn 78 * and captured into GL2PS, where they are drawn over the background image. 79 * Vectorizable props should not draw themselves during the background pass, 80 * and use the vtkOpenGLGL2PSHelper API to draw themselves during the capture 81 * pass. 82 */ 83 vtkGetMacro(ActiveState, State); 84 ///@} 85 86 ///@{ 87 /** 88 * Set/Get the current point size. 89 */ 90 vtkSetMacro(PointSize, float); 91 vtkGetMacro(PointSize, float); 92 ///@} 93 94 ///@{ 95 /** 96 * Set/Get the current line width. 97 */ 98 vtkSetMacro(LineWidth, float); 99 vtkGetMacro(LineWidth, float); 100 ///@} 101 102 ///@{ 103 /** 104 * Set/Get the current line stipple pattern per OpenGL convention. Default is 105 * 0xffff. 106 */ 107 vtkSetMacro(LineStipple, unsigned short); 108 vtkGetMacro(LineStipple, unsigned short); 109 ///@} 110 111 ///@{ 112 /** 113 * Parse the vertex information in tfc and inject primitives into GL2PS. 114 * ren is used to obtain viewport information to complete the vertex 115 * transformation into pixel coordinates, and act/col are used to color the 116 * vertices when tfc does not contain color information. 117 */ 118 virtual void ProcessTransformFeedback( 119 vtkTransformFeedback* tfc, vtkRenderer* ren, vtkActor* act) = 0; 120 virtual void ProcessTransformFeedback( 121 vtkTransformFeedback* tfc, vtkRenderer* ren, unsigned char col[4]) = 0; 122 virtual void ProcessTransformFeedback( 123 vtkTransformFeedback* tfc, vtkRenderer* ren, float col[4]) = 0; 124 ///@} 125 126 /** 127 * Format the text in str according to tprop and instruct GL2PS to draw it at 128 * pixel coordinate pos. Background depth is the z value for the background 129 * quad, and should be in NDC space. 130 * The drawing is always done in the overlay plane. 131 * @sa TextAsPath 132 */ 133 virtual void DrawString(const std::string& str, vtkTextProperty* tprop, double pos[3], 134 double backgroundDepth, vtkRenderer* ren) = 0; 135 136 /** 137 * Generate PS, EPS, or SVG markup from a vtkPath object, and then inject it 138 * into the output using the gl2psSpecial command. The path is translated 139 * uniformly in the scene by windowPos. It is scaled by scale and rotated 140 * counter-clockwise by rotateAngle. The rasterPos is in world coordinates 141 * and determines clipping and depth. If scale is NULL, no scaling is done. 142 * If strokeWidth is positive, the path will be stroked with the indicated 143 * width. If zero or negative, the path will be filled (default). 144 * The label string is inserted into the GL2PS output at the beginning of the 145 * path specification as a comment on supported backends. 146 */ 147 virtual void DrawPath(vtkPath* path, double rasterPos[3], double windowPos[2], 148 unsigned char rgba[4], double scale[2] = nullptr, double rotateAngle = 0.0, 149 float strokeWidth = -1, const char* label = nullptr) = 0; 150 151 /** 152 * Transform the path using the actor's matrix and current GL state, then 153 * draw it to GL2PS. The label string is inserted into the GL2PS output at the 154 * beginning of the path specification as a comment on supported backends. 155 */ 156 virtual void Draw3DPath(vtkPath* path, vtkMatrix4x4* actorMatrix, double rasterPos[3], 157 unsigned char actorColor[4], vtkRenderer* ren, const char* label = nullptr) = 0; 158 159 /** 160 * Draw the image at pos. 161 * Image must be RGB or RGBA with float scalars. 162 */ 163 virtual void DrawImage(vtkImageData* image, double pos[3]) = 0; 164 165 protected: 166 friend class vtkOpenGLGL2PSExporter; 167 168 vtkOpenGLGL2PSHelper(); 169 ~vtkOpenGLGL2PSHelper() override; 170 171 vtkSetMacro(ActiveState, State); 172 vtkSetMacro(TextAsPath, bool); 173 vtkSetMacro(RenderWindow, vtkRenderWindow*); // Doesn't ref count, not needed. 174 vtkSetMacro(PointSizeFactor, float); 175 vtkSetMacro(LineWidthFactor, float); 176 177 static vtkOpenGLGL2PSHelper* Instance; 178 179 vtkRenderWindow* RenderWindow; 180 State ActiveState; 181 bool TextAsPath; 182 float PointSize; 183 float LineWidth; 184 float PointSizeFactor; 185 float LineWidthFactor; 186 unsigned short LineStipple; 187 188 private: 189 vtkOpenGLGL2PSHelper(const vtkOpenGLGL2PSHelper&) = delete; 190 void operator=(const vtkOpenGLGL2PSHelper&) = delete; 191 }; 192 193 #endif // vtkOpenGLGL2PSHelper_h 194