MCPcopy Create free account
hub / github.com/Kitware/VTK / ComputeCellRowsAndCols

Method ComputeCellRowsAndCols

Rendering/Matplotlib/vtkMatplotlibMathTextUtilities.cxx:807–877  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

805
806//------------------------------------------------------------------------------
807bool vtkMatplotlibMathTextUtilities::ComputeCellRowsAndCols(const char* str, PyObject* pyFontProp,
808 int dpi, std::uint64_t& rows, std::uint64_t& cols, vtkSmartPyObject* list)
809{
810 vtkPythonScopeGilEnsurer gilEnsurer;
811
812 // Call the parse method
813 // ftimage, depth = parse(str, dpi, fontProp)
814 vtkSmartPyObject parse(PyUnicode_FromString("parse"));
815 vtkSmartPyObject pyStr(PyUnicode_FromString(str));
816 vtkSmartPyObject pyDpi(PyLong_FromLong(dpi));
817 vtkSmartPyObject resTupleParse(PyObject_CallMethodObjArgs(this->MaskParser, parse.GetPointer(),
818 pyStr.GetPointer(), pyDpi.GetPointer(), pyFontProp, nullptr));
819 if (this->CheckForError(resTupleParse))
820 {
821 return false;
822 }
823
824 // Get ftimage
825 PyObject* ftImage = PyTuple_GetItem(resTupleParse, 5);
826 if (this->CheckForError(ftImage))
827 {
828 return false;
829 }
830
831 // Convert ftimage into a numpy array
832 vtkSmartPyObject numpy(PyImport_ImportModule("numpy"));
833 if (this->CheckForError(numpy))
834 {
835 return false;
836 }
837
838 vtkSmartPyObject asarray(PyUnicode_FromString("asarray"));
839 vtkSmartPyObject numpyArray(
840 PyObject_CallMethodObjArgs(numpy.GetPointer(), asarray.GetPointer(), ftImage, nullptr));
841 if (this->CheckForError(numpyArray))
842 {
843 return false;
844 }
845
846 vtkSmartPyObject dimTuple(PyObject_GetAttrString(numpyArray, "shape"));
847 if (this->CheckForError(dimTuple))
848 {
849 return false;
850 }
851
852 PyArg_ParseTuple(dimTuple, "ii", &rows, &cols);
853 if (this->CheckForError())
854 {
855 return false;
856 }
857
858 // Store python data if needed
859 if (list != nullptr)
860 {
861 vtkSmartPyObject flatArray(
862 PyObject_CallMethod(numpyArray, const_cast<char*>("flatten"), const_cast<char*>("")));
863 if (this->CheckForError(flatArray))
864 {

Callers 2

ComputeRowsAndColsMethod · 0.95
RenderStringMethod · 0.95

Calls 3

CheckForErrorMethod · 0.95
GetPointerMethod · 0.45
TakeReferenceMethod · 0.45

Tested by

no test coverage detected