Slicer 5.13
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
vtkMRMLLayerDMPythonUtil.h
Go to the documentation of this file.
1/*==============================================================================
2
3 Program: 3D Slicer
4
5 Copyright (c) Kitware SAS
6
7 See COPYRIGHT.txt
8 or http://www.slicer.org/copyright/copyright.txt for details.
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15
16 This file was originally developed by Thibault Pelletier, Kitware SAS,
17 and was partially funded by ANR grants ANR-22-CE45-0034 and ANR-18-RHUS-005.
18
19==============================================================================*/
20
21#ifndef __vtkMRMLLayerDMPythonUtil_h
22#define __vtkMRMLLayerDMPythonUtil_h
23#include "vtkSlicerLayerDMModuleMRMLExport.h"
24
25// VTK includes
26#include <vtkObject.h>
27#include <vtkPython.h>
28#include <vtkPythonUtil.h>
29#include <vtkSmartPyObject.h>
30
31// STD includes
32#include <string>
33#include <vector>
34
41class VTK_SLICER_LAYERDM_MODULE_MRML_EXPORT vtkMRMLLayerDMPythonUtil : public vtkObject
42{
43public:
45 vtkTypeMacro(vtkMRMLLayerDMPythonUtil, vtkObject);
46 void PrintSelf(ostream& os, vtkIndent indent) override;
47
51 static PyObject* ToPyObject(vtkObjectBase* obj);
52
56 static PyObject* ToPyObject(unsigned long value);
57
61 static PyObject* ToPyObject(const std::string& value);
62
66 static PyObject* RawPtrToPython(void* ptr);
67
71 static vtkSmartPyObject ToPyArgs(const std::vector<PyObject*>& pyObjs);
72
76 static vtkSmartPyObject ToPyArgs(vtkObjectBase* obj);
77
83 static vtkSmartPyObject ToPyArgs(vtkObject* obj, unsigned long eventId, void* callData);
84
89 static PyObject* CastCallData(PyObject* object, int vtkType);
90
96 static PyObject* CallPythonMethod(PyObject* object, const vtkSmartPyObject& pyArgs, const std::string& fName);
97
102 static PyObject* CallPythonObject(PyObject* object, const vtkSmartPyObject& pyArgs);
103
107 static void SetPythonObject(PyObject** destObject, PyObject* object);
108
111 static void DeletePythonObject(PyObject** destObject);
112
114 static bool IsValidPythonContext();
115
118 static std::string FormatExceptionTraceback();
119
128 static void PrintErrorTraceback(const vtkObject* object, const std::string& errorMsg);
129
135 static std::string GetObjectStr(PyObject* object);
136
137protected:
140};
141
142#endif
static PyObject * ToPyObject(vtkObjectBase *obj)
Convert a VTK object to a Python object.
static void PrintErrorTraceback(const vtkObject *object, const std::string &errorMsg)
Outputs a vtkErrorMacro containing the traceback in case it's not empty.
void PrintSelf(ostream &os, vtkIndent indent) override
static PyObject * CallPythonMethod(PyObject *object, const vtkSmartPyObject &pyArgs, const std::string &fName)
Call a named method on a Python object with arguments.
static vtkSmartPyObject ToPyArgs(const std::vector< PyObject * > &pyObjs)
Create a Python tuple from a vector of Python objects.
static vtkSmartPyObject ToPyArgs(vtkObjectBase *obj)
Create a Python tuple from a single VTK object.
static void DeletePythonObject(PyObject **destObject)
Safely delete a Python object with proper reference counting.
static vtkSmartPyObject ToPyArgs(vtkObject *obj, unsigned long eventId, void *callData)
Create a Python tuple for VTK event callback arguments.
static PyObject * RawPtrToPython(void *ptr)
Convert a raw C pointer to a Python object.
~vtkMRMLLayerDMPythonUtil() override
static bool IsValidPythonContext()
true is python is initialized and no error has occurred.
static std::string FormatExceptionTraceback()
returns the formatted exception string if any exception occurred. Can be used to warn on current erro...
static PyObject * ToPyObject(unsigned long value)
Convert an unsigned long value to a Python object.
static PyObject * CallPythonObject(PyObject *object, const vtkSmartPyObject &pyArgs)
Call a Python callable object with arguments.
static void SetPythonObject(PyObject **destObject, PyObject *object)
Safely set a Python object pointer with proper reference counting.
static std::string GetObjectStr(PyObject *object)
returns the input's PyObject's string representation as std::string. If the python environment is not...
static PyObject * ToPyObject(const std::string &value)
Convert a string value to a Python object.
static vtkMRMLLayerDMPythonUtil * New()
static PyObject * CastCallData(PyObject *object, int vtkType)
Cast call data to appropriate Python type based on VTK type.
_object PyObject