VTK  9.1.20211230
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 class vtkSmartPyObject;
57 class vtkImageData;
58 class vtkPath;
59 class vtkPythonInterpreter;
60 class vtkTextProperty;
61 struct TextColors;
62 
63 class VTKRENDERINGMATPLOTLIB_EXPORT vtkMatplotlibMathTextUtilities : public vtkMathTextUtilities
64 {
65 public:
67  void PrintSelf(ostream& os, vtkIndent indent) override;
68 
70 
71  bool IsAvailable() override;
72 
80  bool GetBoundingBox(vtkTextProperty* tprop, const char* str, int dpi, int bbox[4]) override;
81 
82  bool GetMetrics(
83  vtkTextProperty* tprop, const char* str, int dpi, vtkTextRenderer::Metrics& metrics) override;
84 
96  bool RenderString(const char* str, vtkImageData* image, vtkTextProperty* tprop, int dpi,
97  int textDims[2] = nullptr) override;
98 
106  bool StringToPath(const char* str, vtkPath* path, vtkTextProperty* tprop, int dpi) override;
107 
109 
114  void SetScaleToPowerOfTwo(bool val) override;
115  bool GetScaleToPowerOfTwo() override;
117 
121  vtkSetMacroOverride(InteriorLinesVisibility, bool);
122 
126  vtkSetMacroOverride(InteriorLinesWidth, int);
127 
131  vtkSetVector3MacroOverride(InteriorLinesColor, unsigned char);
132 
133 protected:
136 
140 
142  bool CheckForError(PyObject* object);
143 
150  std::string& str, const std::string& strToFind, const std::string& replacementStr);
151 
152  static constexpr const char* PipeProtectString = "VTK_PROTECT_PIPE";
153 
158  void ComputeTextColors(vtkTextProperty* tprop, TextColors& tcolors);
159 
164 
170 
177 
178  vtkPythonInterpreter* Interpreter;
182 
183  static void GetJustifiedBBox(int rows, int cols, vtkTextProperty* tprop, int bbox[4]);
184 
185  // Rotate the 4 2D corner points by the specified angle (degrees) around the
186  // origin and calculate the bounding box
187  static void RotateCorners(double angleDeg, double corners[4][2], double bbox[4]);
188 
190  bool PrepareImageData(vtkImageData* data, int bbox[4]);
191 
192  std::vector<int> VerticalLinesPosition;
193  std::vector<int> HorizontalLinesPosition;
194 
195  bool InteriorLinesVisibility = false;
196  int InteriorLinesWidth = 1;
197  unsigned char InteriorLinesColor[3] = { 0, 0, 0 };
198 
199 private:
201  void operator=(const vtkMatplotlibMathTextUtilities&) = delete;
202 
207  enum Availability
208  {
209  NOT_TESTED = 0,
210  AVAILABLE,
211  UNAVAILABLE
212  };
213 
220  static Availability CheckMPLAvailability();
221 
223 
226  static Availability MPLMathTextAvailable;
228 
229  typedef std::vector<std::vector<std::string>> GridOfStrings;
230 
237  bool ParseString(const char* str, GridOfStrings& strGrid, std::size_t& maxNumberOfCells);
238 
245  bool ComputeRowsAndCols(const GridOfStrings& strGrid, const std::size_t& maxNumberOfCells,
246  vtkTextProperty* tprop, PyObject* pyFontProp, int dpi, std::uint64_t& rows,
247  std::uint64_t& cols);
248 
254  bool ComputeCellRowsAndCols(const char* cellStr, PyObject* pyFontProp, int dpi,
255  std::uint64_t& rows, std::uint64_t& cols, vtkSmartPyObject* list);
256 
262  bool RenderOneCell(vtkImageData* image, int bbox[4], const std::int64_t rowStart,
263  const std::int64_t colStart, vtkSmartPyObject& pythonData, const std::uint64_t pythonRows,
264  const std::uint64_t pythonCols, const std::uint64_t cellRows, const std::uint64_t cellCols,
265  vtkTextProperty* tprop, const TextColors& tcolors);
266 
270  bool DrawInteriorLines(vtkImageData* image, int bbox[4]);
271 };
272 
273 #endif
topologically and geometrically regular array of data
Definition: vtkImageData.h:157
a simple class to control print indentation
Definition: vtkIndent.h:113
Abstract interface to equation rendering.
Access to MatPlotLib MathText rendering.
vtkSetVector3MacroOverride(InteriorLinesColor, unsigned char)
Set the color of the interior lines between cells.
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 occurence 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.
vtkSetMacroOverride(InteriorLinesWidth, int)
Set the width (in pixels) of the interior lines between cells.
vtkSetMacroOverride(InteriorLinesVisibility, bool)
Set the visibility of the interior lines between cells.
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:33
represent text properties.
@ image
Definition: vtkX3D.h:380
@ data
Definition: vtkX3D.h:321
@ string
Definition: vtkX3D.h:496
struct _object PyObject