VTK
dox/Rendering/Matplotlib/vtkMatplotlibMathTextUtilities.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkMatplotlibMathTextUtilities.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00030 #ifndef __vtkMatplotlibMathTextUtilities_h
00031 #define __vtkMatplotlibMathTextUtilities_h
00032 
00033 #include "vtkRenderingMatplotlibModule.h" // For export macro
00034 #include "vtkMathTextUtilities.h"
00035 
00036 struct _object;
00037 typedef struct _object PyObject;
00038 class vtkImageData;
00039 class vtkPath;
00040 class vtkPythonInterpreter;
00041 class vtkTextProperty;
00042 
00043 class VTKRENDERINGMATPLOTLIB_EXPORT vtkMatplotlibMathTextUtilities :
00044     public vtkMathTextUtilities
00045 {
00046 public:
00047   vtkTypeMacro(vtkMatplotlibMathTextUtilities, vtkMathTextUtilities);
00048   void PrintSelf(ostream& os, vtkIndent indent);
00049 
00050   static vtkMatplotlibMathTextUtilities *New();
00051 
00053 
00055   bool GetBoundingBox(vtkTextProperty *tprop, const char *str,
00056                       unsigned int dpi, int bbox[4]);
00058 
00060 
00065   bool RenderString(const char *str, vtkImageData *data, vtkTextProperty *tprop,
00066                     unsigned int dpi, int textDims[2] = NULL);
00068 
00071   bool StringToPath(const char *str, vtkPath *path, vtkTextProperty *tprop);
00072 
00074 
00077   vtkSetMacro(ScaleToPowerOfTwo, bool);
00078   vtkGetMacro(ScaleToPowerOfTwo, bool);
00080 
00081 protected:
00082   vtkMatplotlibMathTextUtilities();
00083   virtual ~vtkMatplotlibMathTextUtilities();
00084 
00085   bool InitializeMaskParser();
00086   bool InitializePathParser();
00087   bool InitializeFontPropertiesClass();
00088 
00089   bool CheckForError();
00090   bool CheckForError(PyObject *object);
00091 
00094   PyObject * GetFontProperties(vtkTextProperty *tprop);
00095 
00100   void CleanupPythonObjects();
00101 
00102   vtkPythonInterpreter* Interpreter;
00103   PyObject *MaskParser;
00104   PyObject *PathParser;
00105   PyObject *FontPropertiesClass;
00106 
00107   // Rotate the 4 2D corner points by the specified angle (degrees) around the
00108   // origin and calculate the bounding box
00109   void RotateCorners(double angleDeg, double corners[4][2], double bbox[4]);
00110 
00112 
00113   enum Availablity
00114     {
00115     NOT_TESTED = 0,
00116     AVAILABLE,
00117     UNAVAILABLE
00118     };
00120 
00121   bool ScaleToPowerOfTwo;
00122   bool PrepareImageData(vtkImageData *data, int bbox[4]);
00123 
00124   // Function used to check MPL availability and update MPLMathTextAvailable.
00125   // This will do tests only the first time this method is called.
00126   static void CheckMPLAvailability();
00127 
00128 private:
00129   vtkMatplotlibMathTextUtilities(const vtkMatplotlibMathTextUtilities&); // Not implemented.
00130   void operator=(const vtkMatplotlibMathTextUtilities&); // Not implemented.
00131 
00132 
00133   static Availablity MPLMathTextAvailable;
00134 };
00135 
00136 #endif