Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return BSActor2D(obj)
if isinstance(obj, vtk.vtkMapper):
return BSMapper(obj)
if isinstance(obj, vtk.vtkLookupTable):
return BSLookupTable(obj)
if isinstance(obj, vtk.vtkDataSet):
return BSDataSet(obj)
if isinstance(obj, vtk.vtkAlgorithm):
return BSAlgorithm(obj)
# Fall back to generic wrapper
return BSVTKObjectWrapper(obj)
"""
def __init__(self, vtkobject=None, **kwargs):
super().__init__(vtkobject=vtkobject, **kwargs)
class BSTextActor(BSTexturedActor2D):
"""Wrapper for vtkTextActor.
Unresolved requests are forwarded to its 2D property.
"""
def __init__(self, vtkobject=None, **kwargs):
super().__init__(vtkobject=vtkobject, **kwargs)
class BSActor(BSVTKObjectWrapper):
"""Wrapper for vtkActor.
Unresolved requests are forwarded to its property.
Examples
--------
>>> from brainspace.vtk_interface.wrappers import BSActor
>>> a = BSActor()
>>> a.GetProperty().GetOpacity()
1.0
>>> a.GetOpacity() # It is forwarded to the property
1.0
>>> a.opacity = .5
>>> a.VTKObject.GetProperty().GetOpacity()
0.5
"""
"""
kwargs = dict(zip(args, [None] * len(args)), **kwargs)
output = {}
for k, v in kwargs.items():
output[k] = self._handle_call('get', k, v)
return output
@property
def vtk_map(self):
"""dict: Dictionary of vtk setter and getter methods."""
return self._vtk_map[self.VTKObject.__vtkname__]
class BSAlgorithm(BSVTKObjectWrapper):
"""Wrapper for vtkAlgorithm.
"""
def __init__(self, vtkobject, **kwargs):
super().__init__(vtkobject, **kwargs)
@property
def nip(self):
"""int: Returns number of input ports"""
return self.GetNumberOfInputPorts()
@property
def nop(self):
"""int: Returns number of output ports"""
return self.GetNumberOfOutputPorts()
Wraps the `AddInputDataObject` function of `vtkAlgorithm` to
accept a vtk object or a wrapped object.
Parameters
----------
args : list of arguments
Arguments to be passed to the `AddInputDataObject` method of the
vtk object.
"""
self.VTKObject.AddInputDataObject(*args)
# Wrap vtk data objects from dataset_adapter
class BSDataObject(dsa.DataObject, BSVTKObjectWrapper):
"""Wrapper for vtkDataObject."""
def __init__(self, vtkobject=None):
super().__init__(vtkobject)
@property
def field_keys(self):
"""list of str: Returns keys of field data."""
return self.FieldData.keys()
@property
def n_field_data(self):
"""int: Returns number of entries in field data."""
return len(self.FieldData.keys())
@unwrap_input(0, skip=True)
def SetInputData(self, poly_data):
"""Set input data.
Wraps the `SetInput` method of `vtkPolyDataMapper` to accept
a vtkPolyData of BSPolyData.
Parameters
----------
poly_data : vtkPolyData or BSPolyData
Input poly data.
"""
self.VTKObject.SetInputData(poly_data)
class BSActor2D(BSVTKObjectWrapper):
"""Wrapper for vtkActor2D.
Unresolved requests are forwarded to its 2D property.
"""
def __init__(self, vtkobject=None, **kwargs):
super().__init__(vtkobject=vtkobject, **kwargs)
self._property = BSWrapVTKObject(self.VTKObject.GetProperty())
def _handle_call(self, key, name, args):
try:
return super()._handle_call(key, name, args)
except (AttributeError, KeyError):
return self._property._handle_call(key, name, args)
def __getattr__(self, name):
def GetProperty(self):
"""Get property.
Wraps the `GetProperty` method of `vtkActor` to return a wrapped
property.
Returns
-------
prop : BSVTKObjectWrapper
Actor's property.
"""
return self._property
class BSViewport(BSVTKObjectWrapper):
"""Wrapper for vtkViewport."""
def __init__(self, vtkobject=None, **kwargs):
super().__init__(vtkobject=vtkobject, **kwargs)
def AddActor2D(self, actor, **kwargs):
"""Set mapper.
Wraps the `AddActor2D` method of `vtkViewport` to accept a
`vtkActor2D` or BSActor2D.
Parameters
----------
actor : vtkActor or BSActor
2D Actor.
kwargs : optional keyword arguments