36#include <vtkUnstructuredGrid.h>
37#include <vtkVersion.h>
52 return py::incref(Py_None);
54 std::ostringstream oss;
55 oss << (vtkObjectBase *)
p;
56 std::string address_str = oss.str();
60 py::object obj = py::import(
"vtkmodules.vtkCommonCore")
61 .attr(
"vtkObjectBase")(address_str);
62 return py::incref(obj.ptr());
64 catch (py::error_already_set &)
74 py::import(
"vtk").attr(
"vtkObjectBase")(address_str);
75 return py::incref(obj.ptr());
77 catch (py::error_already_set &)
80 throw NekError(
"Unable to import VTK.");
83 return py::incref(py::object().ptr());
95 std::string thisStr =
"__this__";
98 if (!PyObject_HasAttrString(obj, thisStr.c_str()))
103 PyObject *thisAttr = PyObject_GetAttrString(obj, thisStr.c_str());
104 if (thisAttr ==
nullptr)
109#if PY_MAJOR_VERSION == 2
110 std::string str = PyString_AsString(thisAttr);
112 std::string str = PyUnicode_AsUTF8(thisAttr);
120 char hex_address[32], *pEnd;
121 auto iter = str.find(
"_p_vtk");
123 if (iter == std::string::npos)
128 auto className = str.substr(iter).find(
"vtk");
129 if (className == std::string::npos)
134 long address = stol(str.substr(1, 17));
135 vtkObjectBase *vtkObject = (vtkObjectBase *)((
void *)address);
137 if (vtkObject->IsA(str.substr(className).c_str()))
145#define VTK_PYTHON_CONVERSION(type) \
147 py::to_python_converter<type *, vtkObjectPointer_to_python<type *>>(); \
149 py::converter::registry::insert(&extract_vtk_wrapped_pointer, \
150 py::type_id<type>());
Nektar::ErrorUtil::NekError NekError
void * extract_vtk_wrapped_pointer(PyObject *obj)
static PyObject * convert(const T &p)