VTK
vtkMatplotlibMathTextUtilities.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkMatplotlibMathTextUtilities.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 =========================================================================*/
28 #ifndef vtkMatplotlibMathTextUtilities_h
29 #define vtkMatplotlibMathTextUtilities_h
30 
31 #include "vtkRenderingMatplotlibModule.h" // For export macro
32 #include "vtkMathTextUtilities.h"
33 
34 struct _object;
35 typedef struct _object PyObject;
36 class vtkImageData;
37 class vtkPath;
38 class vtkPythonInterpreter;
39 class vtkTextProperty;
40 
41 class VTKRENDERINGMATPLOTLIB_EXPORT vtkMatplotlibMathTextUtilities :
43 {
44 public:
46  void PrintSelf(ostream& os, vtkIndent indent) override;
47 
49 
50  bool IsAvailable() override;
51 
59  bool GetBoundingBox(vtkTextProperty *tprop, const char *str, int dpi,
60  int bbox[4]) override;
61 
62  bool GetMetrics(vtkTextProperty *tprop, const char *str, int dpi,
63  vtkTextRenderer::Metrics &metrics) override;
64 
75  bool RenderString(const char *str, vtkImageData *data, vtkTextProperty *tprop,
76  int dpi, int textDims[2] = NULL) override;
77 
84  bool StringToPath(const char *str, vtkPath *path, vtkTextProperty *tprop,
85  int dpi) override;
86 
88 
93  void SetScaleToPowerOfTwo(bool val) override;
94  bool GetScaleToPowerOfTwo() override;
96 
97 protected:
100 
101  bool InitializeMaskParser();
102  bool InitializePathParser();
103  bool InitializeFontPropertiesClass();
104 
105  bool CheckForError();
106  bool CheckForError(PyObject *object);
107 
112  PyObject * GetFontProperties(vtkTextProperty *tprop);
113 
119  void CleanupPythonObjects();
120 
121  vtkPythonInterpreter* Interpreter;
125 
126  static void GetJustifiedBBox(int rows, int cols, vtkTextProperty *tprop,
127  int bbox[4]);
128 
129  // Rotate the 4 2D corner points by the specified angle (degrees) around the
130  // origin and calculate the bounding box
131  static void RotateCorners(double angleDeg, double corners[4][2],
132  double bbox[4]);
133 
135  bool PrepareImageData(vtkImageData *data, int bbox[4]);
136 
137 private:
139  void operator=(const vtkMatplotlibMathTextUtilities&) = delete;
140 
145  enum Availability
146  {
147  NOT_TESTED = 0,
148  AVAILABLE,
149  UNAVAILABLE
150  };
151 
158  static Availability CheckMPLAvailability();
159 
161 
164  static Availability MPLMathTextAvailable;
165 };
167 
168 #endif
vtkMathTextUtilities::IsAvailable
virtual bool IsAvailable()
Returns true if mathtext rendering is available.
Definition: vtkMathTextUtilities.h:63
vtkMatplotlibMathTextUtilities
Access to MatPlotLib MathText rendering.
Definition: vtkMatplotlibMathTextUtilities.h:41
vtkMathTextUtilities::GetMetrics
virtual bool GetMetrics(vtkTextProperty *tprop, const char *str, int dpi, vtkTextRenderer::Metrics &metrics)=0
Return the metrics for the rendered str, tprop, and dpi.
vtkX3D::data
Definition: vtkX3D.h:315
vtkPath
concrete dataset representing a path defined by Bezier curves.
Definition: vtkPath.h:35
vtkMatplotlibMathTextUtilities::MaskParser
PyObject * MaskParser
Definition: vtkMatplotlibMathTextUtilities.h:122
vtkMathTextUtilities
Abstract interface to equation rendering.
Definition: vtkMathTextUtilities.h:54
PyObject
struct _object PyObject
Definition: vtkMatplotlibMathTextUtilities.h:35
vtkMathTextUtilities::GetScaleToPowerOfTwo
virtual bool GetScaleToPowerOfTwo()=0
Set to true if the graphics implementation requires texture image dimensions to be a power of two.
vtkMathTextUtilities::StringToPath
virtual bool StringToPath(const char *str, vtkPath *path, vtkTextProperty *tprop, int dpi)=0
Parse the MathText expression in str and fill path with a contour of the glyphs.
vtkMathTextUtilities::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkImageData
topologically and geometrically regular array of data
Definition: vtkImageData.h:45
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkMatplotlibMathTextUtilities::FontPropertiesClass
PyObject * FontPropertiesClass
Definition: vtkMatplotlibMathTextUtilities.h:124
vtkMatplotlibMathTextUtilities::PathParser
PyObject * PathParser
Definition: vtkMatplotlibMathTextUtilities.h:123
vtkMathTextUtilities::GetBoundingBox
virtual bool GetBoundingBox(vtkTextProperty *tprop, const char *str, int dpi, int bbox[4])=0
Determine the dimensions of the image that RenderString will produce for a given str,...
vtkTextProperty
represent text properties.
Definition: vtkTextProperty.h:39
vtkMathTextUtilities.h
vtkMathTextUtilities::SetScaleToPowerOfTwo
virtual void SetScaleToPowerOfTwo(bool scale)=0
vtkMathTextUtilities::New
static vtkMathTextUtilities * New()
This is a singleton pattern New.
vtkTextRenderer::Metrics
Definition: vtkTextRenderer.h:78
vtkMatplotlibMathTextUtilities::Interpreter
vtkPythonInterpreter * Interpreter
Definition: vtkMatplotlibMathTextUtilities.h:121
vtkMatplotlibMathTextUtilities::ScaleToPowerOfTwo
bool ScaleToPowerOfTwo
Definition: vtkMatplotlibMathTextUtilities.h:134
vtkMathTextUtilities::RenderString
virtual bool RenderString(const char *str, vtkImageData *data, vtkTextProperty *tprop, int dpi, int textDims[2]=nullptr)=0
Render the given string str into the vtkImageData data with a resolution of dpi.