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 Class Reference

Utility class for Python/C++ interoperability in VTK MRML Layer Displayable Manager. More...

#include <Modules/Loadable/LayerDM/MRML/vtkMRMLLayerDMPythonUtil.h>

Inheritance diagram for vtkMRMLLayerDMPythonUtil:
Collaboration diagram for vtkMRMLLayerDMPythonUtil:

Public Types

typedef vtkObject Superclass
 

Public Member Functions

virtual const char * GetClassName ()
 
virtual int IsA (const char *type)
 
void PrintSelf (ostream &os, vtkIndent indent) override
 

Static Public Member Functions

static PyObject * CallPythonMethod (PyObject *object, const vtkSmartPyObject &pyArgs, const std::string &fName)
 Call a named method on a Python object with arguments.
 
static PyObject * CallPythonObject (PyObject *object, const vtkSmartPyObject &pyArgs)
 Call a Python callable object with arguments.
 
static PyObject * CastCallData (PyObject *object, int vtkType)
 Cast call data to appropriate Python type based on VTK type.
 
static void DeletePythonObject (PyObject **destObject)
 Safely delete a Python object with proper reference counting.
 
static std::string FormatExceptionTraceback ()
 returns the formatted exception string if any exception occurred. Can be used to warn on current errors without swallowing the exception.
 
static std::string GetObjectStr (PyObject *object)
 returns the input's PyObject's string representation as std::string. If the python environment is not initialized, returns empty string. If the input object is nullptr, returns "None" If the input object string representation fails, return "INVALID_OBJECT_STR" Calling this method doesn't change the current python error stack.
 
static int IsTypeOf (const char *type)
 
static bool IsValidPythonContext ()
 true is python is initialized and no error has occurred.
 
static vtkMRMLLayerDMPythonUtil * New ()
 
static void PrintErrorTraceback (const vtkObject *object, const std::string &errorMsg)
 Outputs a vtkErrorMacro containing the traceback in case it's not empty.
 
static PyObject * RawPtrToPython (void *ptr)
 Convert a raw C pointer to a Python object.
 
static vtkMRMLLayerDMPythonUtil * SafeDownCast (vtkObject *o)
 
static void SetPythonObject (PyObject **destObject, PyObject *object)
 Safely set a Python object pointer with proper reference counting.
 
static vtkSmartPyObject ToPyArgs (const std::vector< PyObject * > &pyObjs)
 Create a Python tuple from a vector of Python objects.
 
static vtkSmartPyObject ToPyArgs (vtkObject *obj, unsigned long eventId, void *callData)
 Create a Python tuple for VTK event callback arguments.
 
static vtkSmartPyObject ToPyArgs (vtkObjectBase *obj)
 Create a Python tuple from a single VTK object.
 
static PyObject * ToPyObject (const std::string &value)
 Convert a string value to a Python object.
 
static PyObject * ToPyObject (unsigned long value)
 Convert an unsigned long value to a Python object.
 
static PyObject * ToPyObject (vtkObjectBase *obj)
 Convert a VTK object to a Python object.
 

Protected Member Functions

 vtkMRMLLayerDMPythonUtil ()
 
 ~vtkMRMLLayerDMPythonUtil () override
 

Detailed Description

Utility class for Python/C++ interoperability in VTK MRML Layer Displayable Manager.

This class provides a collection of static utility methods for converting between VTK C++ objects and Python objects, managing Python object lifecycles, and calling Python methods from C++. It serves as a bridge layer for Python integration in the Layer Displayable Manager module.

Definition at line 41 of file vtkMRMLLayerDMPythonUtil.h.

Member Typedef Documentation

◆ Superclass

Definition at line 45 of file vtkMRMLLayerDMPythonUtil.h.

Constructor & Destructor Documentation

◆ vtkMRMLLayerDMPythonUtil()

vtkMRMLLayerDMPythonUtil::vtkMRMLLayerDMPythonUtil ( )
protected

◆ ~vtkMRMLLayerDMPythonUtil()

vtkMRMLLayerDMPythonUtil::~vtkMRMLLayerDMPythonUtil ( )
overrideprotected

Member Function Documentation

◆ CallPythonMethod()

static PyObject * vtkMRMLLayerDMPythonUtil::CallPythonMethod ( PyObject * object,
const vtkSmartPyObject & pyArgs,
const std::string & fName )
static

Call a named method on a Python object with arguments.

Parameters
objectPython object on which to call the method
pyArgsPython tuple of arguments to pass to the method
fNameName of the method to call
Returns
PyObject* Return value from the Python method call

◆ CallPythonObject()

static PyObject * vtkMRMLLayerDMPythonUtil::CallPythonObject ( PyObject * object,
const vtkSmartPyObject & pyArgs )
static

Call a Python callable object with arguments.

Parameters
objectPython callable object to invoke
pyArgsPython tuple of arguments to pass
Returns
PyObject* Return value from the Python callable

◆ CastCallData()

static PyObject * vtkMRMLLayerDMPythonUtil::CastCallData ( PyObject * object,
int vtkType )
static

Cast call data to appropriate Python type based on VTK type.

Parameters
objectPython object to cast
vtkTypeVTK type identifier to cast to
Returns
PyObject* Casted Python object

◆ DeletePythonObject()

static void vtkMRMLLayerDMPythonUtil::DeletePythonObject ( PyObject ** destObject)
static

Safely delete a Python object with proper reference counting.

Parameters
destObjectPointer to PyObject pointer to delete and set to nullptr

◆ FormatExceptionTraceback()

static std::string vtkMRMLLayerDMPythonUtil::FormatExceptionTraceback ( )
static

returns the formatted exception string if any exception occurred. Can be used to warn on current errors without swallowing the exception.

◆ GetClassName()

virtual const char * vtkMRMLLayerDMPythonUtil::GetClassName ( )
virtual

◆ GetObjectStr()

static std::string vtkMRMLLayerDMPythonUtil::GetObjectStr ( PyObject * object)
static

returns the input's PyObject's string representation as std::string. If the python environment is not initialized, returns empty string. If the input object is nullptr, returns "None" If the input object string representation fails, return "INVALID_OBJECT_STR" Calling this method doesn't change the current python error stack.

◆ IsA()

virtual int vtkMRMLLayerDMPythonUtil::IsA ( const char * type)
virtual

◆ IsTypeOf()

static int vtkMRMLLayerDMPythonUtil::IsTypeOf ( const char * type)
static

◆ IsValidPythonContext()

static bool vtkMRMLLayerDMPythonUtil::IsValidPythonContext ( )
static

true is python is initialized and no error has occurred.

◆ New()

static vtkMRMLLayerDMPythonUtil * vtkMRMLLayerDMPythonUtil::New ( )
static

◆ PrintErrorTraceback()

static void vtkMRMLLayerDMPythonUtil::PrintErrorTraceback ( const vtkObject * object,
const std::string & errorMsg )
static

Outputs a vtkErrorMacro containing the traceback in case it's not empty.

Does nothing if the python environment is not initialized. Should be used by Methods that cannot properly forward Python results back to the interpreter to avoid silent errors happening in the Python layer (or errors being raised in unrelated parts of the executable).

This method doesn't swallow the underlying python exception. Python level exceptions should be handled at the python level where they are raised to avoid silent errors from happening.

◆ PrintSelf()

void vtkMRMLLayerDMPythonUtil::PrintSelf ( ostream & os,
vtkIndent indent )
override

◆ RawPtrToPython()

static PyObject * vtkMRMLLayerDMPythonUtil::RawPtrToPython ( void * ptr)
static

Convert a raw C pointer to a Python object.

Parameters
ptrRaw pointer to convert
Returns
PyObject* Python object wrapping the pointer

◆ SafeDownCast()

static vtkMRMLLayerDMPythonUtil * vtkMRMLLayerDMPythonUtil::SafeDownCast ( vtkObject * o)
static

◆ SetPythonObject()

static void vtkMRMLLayerDMPythonUtil::SetPythonObject ( PyObject ** destObject,
PyObject * object )
static

Safely set a Python object pointer with proper reference counting.

Parameters
destObjectPointer to destination PyObject pointer to update
objectSource Python object to assign

◆ ToPyArgs() [1/3]

static vtkSmartPyObject vtkMRMLLayerDMPythonUtil::ToPyArgs ( const std::vector< PyObject * > & pyObjs)
static

Create a Python tuple from a vector of Python objects.

Parameters
pyObjsVector of Python objects to package as arguments
Returns
vtkSmartPyObject Smart pointer to Python tuple containing the objects

◆ ToPyArgs() [2/3]

static vtkSmartPyObject vtkMRMLLayerDMPythonUtil::ToPyArgs ( vtkObject * obj,
unsigned long eventId,
void * callData )
static

Create a Python tuple for VTK event callback arguments.

Parameters
objVTK object that triggered the event
eventIdEvent identifier
callDataAdditional event-specific data
Returns
vtkSmartPyObject Smart pointer to Python tuple containing the event arguments

◆ ToPyArgs() [3/3]

static vtkSmartPyObject vtkMRMLLayerDMPythonUtil::ToPyArgs ( vtkObjectBase * obj)
static

Create a Python tuple from a single VTK object.

Parameters
objVTK object base pointer to package as arguments
Returns
vtkSmartPyObject Smart pointer to Python tuple containing the object

◆ ToPyObject() [1/3]

static PyObject * vtkMRMLLayerDMPythonUtil::ToPyObject ( const std::string & value)
static

Convert a string value to a Python object.

Parameters
valuestring value to convert
Returns
PyObject* Python object representation of the value

◆ ToPyObject() [2/3]

static PyObject * vtkMRMLLayerDMPythonUtil::ToPyObject ( unsigned long value)
static

Convert an unsigned long value to a Python object.

Parameters
valueUnsigned long value to convert
Returns
PyObject* Python object representation of the value

◆ ToPyObject() [3/3]

static PyObject * vtkMRMLLayerDMPythonUtil::ToPyObject ( vtkObjectBase * obj)
static

Convert a VTK object to a Python object.

Parameters
objVTK object base pointer to convert
Returns
PyObject* Python object representation of the VTK object

The documentation for this class was generated from the following file: