brainspace.vtk_interface.wrappers.base.BSVTKObjectWrapper

class brainspace.vtk_interface.wrappers.base.BSVTKObjectWrapper(vtkobject, **kwargs)[source]

Base class for all classes that wrap VTK objects.

Adapted from dataset_adapter, with additional setVTK and getVTK methods. Create an instance if class is passed instead of object.

This class holds a reference to the wrapped VTK object. It also forwards unresolved methods to the underlying object by overloading __getattr__. This class also supports all VTK setters and getters to be used like properties/attributes dropping the get/set prefix. This is case insensitive.

Parameters:
  • vtkobject (type or object) – VTK class or object.
  • kwargs (optional keyword parameters) – Parameters used to invoke set methods on the vtk object.
Variables:

VTKObject (vtkObject) – A VTK object.

Examples

>>> from vtkmodules.vtkRenderingCorePython import vtkPolyDataMapper
>>> from brainspace.vtk_interface.wrappers import BSVTKObjectWrapper
>>> m1 = BSVTKObjectWrapper(vtkPolyDataMapper())
>>> m1
<brainspace.vtk_interface.base.BSVTKObjectWrapper at 0x7f38a4b70198>
>>> m1.VTKObject
(vtkRenderingOpenGL2Python.vtkOpenGLPolyDataMapper)0x7f38a4bee888

Passing class and additional keyword arguments:

>>> m2 = BSVTKObjectWrapper(vtkPolyDataMapper, arrayId=3,
...                         colorMode='mapScalars')
>>> # Get color name, these are all the same
>>> m2.VTKObject.GetColorModeAsString()
'MapScalars'
>>> m2.GetColorModeAsString()
'MapScalars'
>>> m2.colorModeAsString
'MapScalars'
>>> # Get array id
>>> m2.VTKObject.GetArrayId()
3
>>> m2.GetArrayId()
3
>>> m2.arrayId
3

We can change array id and color mode as follows:

>>> m2.arrayId = 0
>>> m2.VTKObject.GetArrayId()
0
>>> m2.colorMode = 'default'
>>> m2.VTKObject.GetColorModeAsString()
'Default'
__init__(vtkobject, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(vtkobject, **kwargs) Initialize self.
getVTK(*args, **kwargs) Invoke get methods on the vtk object.
setVTK(*args, **kwargs) Invoke set methods on the vtk object.

Attributes

vtk_map Dictionary of vtk setter and getter methods.
getVTK(*args, **kwargs)[source]

Invoke get methods on the vtk object.

Parameters:
  • args (list of str) – Method that require no arguments.
  • kwargs (list of keyword-value arguments) – key-word arguments can be use for methods that require arguments. When several arguments are required, use a tuple. Methods that require no arguments can also be used here using None as the argument.
Returns:

results (dict) – Dictionary of results where the keys are the method names and the values the results.

Examples

>>> import vtk
>>> from brainspace.vtk_interface.wrappers import BSVTKObjectWrapper
>>> m1 = BSVTKObjectWrapper(vtk.vtkPolyDataMapper())
>>> m1.getVTK('arrayId', colorModeAsString=None)
{'arrayId': -1, 'colorModeAsString': 'Default'}
>>> m1.getVTK('colorModeAsString', arrayId=None)
{'colorModeAsString': 'Default', 'arrayId': -1}
>>> m1.getVTK(numberOfInputConnections=0)
{'numberOfInputConnections': 0}
setVTK(*args, **kwargs)[source]

Invoke set methods on the vtk object.

Parameters:
  • args (list of str) – Setter methods that require no arguments.
  • kwargs (list of keyword-value arguments) – key-word arguments can be use for methods that require arguments. When several arguments are required, use a tuple. Methods that require no arguments can also be used here using None as the argument.
Returns:

self (BSVTKObjectWrapper object) – Return self.

Examples

>>> import vtk
>>> from brainspace.vtk_interface.wrappers import BSVTKObjectWrapper
>>> m1 = BSVTKObjectWrapper(vtk.vtkPolyDataMapper())
>>> m1.setVTK(arrayId=3, colorMode='mapScalars')
<brainspace.vtk_interface.base.BSVTKObjectWrapper at 0x7f38a4ace320>
>>> m1.arrayId
3
>>> m1.colorModeAsString
'MapScalars'
vtk_map

Dictionary of vtk setter and getter methods.

Type:dict