VTK  9.2.20221001
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 =========================================================================*/
46 #ifndef vtkMatplotlibMathTextUtilities_h
47 #define vtkMatplotlibMathTextUtilities_h
48 
49 #include "vtkMathTextUtilities.h"
50 #include "vtkRenderingMatplotlibModule.h" // For export macro
51 
52 #include <vector> // for std::vector
53 
54 struct _object;
55 typedef struct _object PyObject;
56 
57 VTK_ABI_NAMESPACE_BEGIN
58 class vtkImageData;
59 class vtkPath;
60 class vtkPythonInterpreter;
61 class vtkSmartPyObject;
62 class vtkTextProperty;
63 struct TextColors;
64 
65 class VTKRENDERINGMATPLOTLIB_EXPORT vtkMatplotlibMathTextUtilities : public vtkMathTextUtilities
66 {
67 public:
69  void PrintSelf(ostream& os, vtkIndent indent) override;
70 
72 
73  bool IsAvailable() override;
74 
82  bool GetBoundingBox(vtkTextProperty* tprop, const char* str, int dpi, int bbox[4]) override;
83 
84  bool GetMetrics(
85  vtkTextProperty* tprop, const char* str, int dpi, vtkTextRenderer::Metrics& metrics) override;
86 
98  bool RenderString(const char* str, vtkImageData* image, vtkTextProperty* tprop, int dpi,
99  int textDims[2] = nullptr) override;
100 
108  bool StringToPath(const char* str, vtkPath* path, vtkTextProperty* tprop, int dpi) override;
109 
111 
116  void SetScaleToPowerOfTwo(bool val) override;
117  bool GetScaleToPowerOfTwo() override;
119 
120 protected:
123 
127 
129  bool CheckForError(PyObject* object);
130 
137  std::string& str, const std::string& strToFind, const std::string& replacementStr);
138 
139  static constexpr const char* PipeProtectString = "VTK_PROTECT_PIPE";
140 
145  void ComputeTextColors(vtkTextProperty* tprop, TextColors& tcolors);
146 
151 
157 
164 
165  vtkPythonInterpreter* Interpreter;
169 
170  static void GetJustifiedBBox(int rows, int cols, vtkTextProperty* tprop, int bbox[4]);
171 
172  // Rotate the 4 2D corner points by the specified angle (degrees) around the
173  // origin and calculate the bounding box
174  static void RotateCorners(double angleDeg, double corners[4][2], double bbox[4]);
175 
177  bool PrepareImageData(vtkImageData* data, int bbox[4]);
178 
179  std::vector<int> VerticalLinesPosition;
180  std::vector<int> HorizontalLinesPosition;
181 
182 private:
184  void operator=(const vtkMatplotlibMathTextUtilities&) = delete;
185 
190  enum Availability
191  {
192  NOT_TESTED = 0,
193  AVAILABLE,
194  UNAVAILABLE
195  };
196 
203  static Availability CheckMPLAvailability();
204 
206 
209  static Availability MPLMathTextAvailable;
211 
212  typedef std::vector<std::vector<std::string>> GridOfStrings;
213 
220  bool ParseString(const char* str, GridOfStrings& strGrid, std::size_t& maxNumberOfCells);
221 
228  bool ComputeRowsAndCols(const GridOfStrings& strGrid, const std::size_t& maxNumberOfCells,
229  vtkTextProperty* tprop, PyObject* pyFontProp, int dpi, std::uint64_t& rows,
230  std::uint64_t& cols);
231 
237  bool ComputeCellRowsAndCols(const char* cellStr, PyObject* pyFontProp, int dpi,
238  std::uint64_t& rows, std::uint64_t& cols, vtkSmartPyObject* list);
239 
245  bool RenderOneCell(vtkImageData* image, int bbox[4], const std::int64_t rowStart,
246  const std::int64_t colStart, vtkSmartPyObject& pythonData, const std::uint64_t pythonRows,
247  const std::uint64_t pythonCols, const std::uint64_t cellRows, const std::uint64_t cellCols,
248  vtkTextProperty* tprop, const TextColors& tcolors);
249 
253  bool DrawInteriorLines(vtkImageData* image, int bbox[4], vtkTextProperty* tprop);
254 };
255 
256 VTK_ABI_NAMESPACE_END
257 #endif
topologically and geometrically regular array of data
Definition: vtkImageData.h:164
a simple class to control print indentation
Definition: vtkIndent.h:120
Abstract interface to equation rendering.
Access to MatPlotLib MathText rendering.
bool GetBoundingBox(vtkTextProperty *tprop, const char *str, int dpi, int bbox[4]) override
Given a text property and a string, get the bounding box {xmin, xmax, ymin, ymax} of the rendered str...
bool GetMetrics(vtkTextProperty *tprop, const char *str, int dpi, vtkTextRenderer::Metrics &metrics) override
Return the metrics for the rendered str, tprop, and dpi.
void ComputeTextColors(vtkTextProperty *tprop, TextColors &tcolors)
Compute rgba values of the foreground, background and frame of the text property.
void FindAndReplaceInString(std::string &str, const std::string &strToFind, const std::string &replacementStr)
Replace each occurrence of strToFind in str by replacementStr.
bool SetMathTextFont(vtkTextProperty *tprop)
Modify matplotlib.rcParams to customize math text font.
static void GetJustifiedBBox(int rows, int cols, vtkTextProperty *tprop, int bbox[4])
bool CheckForError(PyObject *object)
void CleanupPythonObjects()
Cleanup and destroy any python objects.
static vtkMatplotlibMathTextUtilities * New()
bool RenderString(const char *str, vtkImageData *image, vtkTextProperty *tprop, int dpi, int textDims[2]=nullptr) override
Render the given string str into the vtkImageData image with a resolution of dpi.
PyObject * GetFontProperties(vtkTextProperty *tprop)
Returns a matplotlib.font_manager.FontProperties PyObject, initialized from the vtkTextProperty tprop...
bool StringToPath(const char *str, vtkPath *path, vtkTextProperty *tprop, int dpi) override
Parse the MathText expression in str and fill path with a contour of the glyphs.
bool IsAvailable() override
Returns true if mathtext rendering is available.
static void RotateCorners(double angleDeg, double corners[4][2], double bbox[4])
~vtkMatplotlibMathTextUtilities() override
void SetScaleToPowerOfTwo(bool val) override
Set to true if the graphics implementation requires texture image dimensions to be a power of two.
bool PrepareImageData(vtkImageData *data, int bbox[4])
bool GetScaleToPowerOfTwo() override
Set to true if the graphics implementation requires texture image dimensions to be a power of two.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
concrete dataset representing a path defined by Bezier curves.
Definition: vtkPath.h:37
represent text properties.
@ image
Definition: vtkX3D.h:386
@ data
Definition: vtkX3D.h:327
@ string
Definition: vtkX3D.h:502
struct _object PyObject