Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if not is_vtk(obj):
raise ValueError('Unknown object type: {0}'.format(type(obj)))
# Is this really needed? is there a vtk class that doesn't start with vtk?
if not obj.__vtkname__.startswith('vtk'):
raise ValueError('Unknown object type: {0}'.format(type(obj)))
# Find wrapper for vtk class or one of its superclasses
for c in [sc.__vtkname__[3:] for sc in obj.__class__.mro()[:-3]]:
if c in BSVTKObjectWrapperMeta.entries:
bs_cls = BSVTKObjectWrapperMeta.entries[c]
return bs_cls(obj)
# Fall back to generic wrapper
return BSVTKObjectWrapper(obj)
"""
Misc wrappers for some VTK classes.
"""
# Author: Oualid Benkarim
# License: BSD 3 clause
from vtk.util.vtkConstants import VTK_ID_TYPE
from .base import BSVTKObjectWrapper
from ..decorators import unwrap_input, wrap_output
class BSCollection(BSVTKObjectWrapper):
"""Wrapper for vtkCollection."""
def __init__(self, vtkobject=None, **kwargs):
super().__init__(vtkobject, **kwargs)
@property
def n_items(self):
return self.VTKObject.GetNumberOfItems()
@wrap_output
def __getitem__(self, i):
if i < 0:
i += self.n_items
return self.VTKObject.GetItemAsObject(i)
def __setitem__(self, i, obj):
if i < 0:
############################################################
# Coordinate object
############################################################
class BSCoordinate(BSVTKObjectWrapper):
"""Wrapper for vtkCoordinate."""
def __init__(self, vtkobject=None, **kwargs):
super().__init__(vtkobject, **kwargs)
############################################################
# Cell Array
############################################################
class BSCellArray(BSVTKObjectWrapper):
"""Wrapper for vtkCellArray."""
def __init__(self, vtkobject=None, **kwargs):
super().__init__(vtkobject=vtkobject, **kwargs)
@unwrap_input(2, vtype={2: VTK_ID_TYPE})
def SetCells(self, n_cells, cells):
self.VTKObject.SetCells(n_cells, cells)
############################################################
# GL2PS Exporter
############################################################
class BSGL2PSExporter(BSVTKObjectWrapper):
"""Wrapper for vtkGL2PSExporter."""
############################################################
class BSCellArray(BSVTKObjectWrapper):
"""Wrapper for vtkCellArray."""
def __init__(self, vtkobject=None, **kwargs):
super().__init__(vtkobject=vtkobject, **kwargs)
@unwrap_input(2, vtype={2: VTK_ID_TYPE})
def SetCells(self, n_cells, cells):
self.VTKObject.SetCells(n_cells, cells)
############################################################
# GL2PS Exporter
############################################################
class BSGL2PSExporter(BSVTKObjectWrapper):
"""Wrapper for vtkGL2PSExporter."""
def __init__(self, vtkobject=None, **kwargs):
super().__init__(vtkobject=vtkobject, **kwargs)
class BSPolyDataCollection(BSCollection):
"""Wrapper for vtkPolyDataCollection."""
pass
class BSTextPropertyCollection(BSCollection):
"""Wrapper for vtkTextPropertyCollection."""
pass
############################################################
# Coordinate object
############################################################
class BSCoordinate(BSVTKObjectWrapper):
"""Wrapper for vtkCoordinate."""
def __init__(self, vtkobject=None, **kwargs):
super().__init__(vtkobject, **kwargs)
############################################################
# Cell Array
############################################################
class BSCellArray(BSVTKObjectWrapper):
"""Wrapper for vtkCellArray."""
def __init__(self, vtkobject=None, **kwargs):
super().__init__(vtkobject=vtkobject, **kwargs)
@unwrap_input(2, vtype={2: VTK_ID_TYPE})
def is_wrapper(obj):
""" Check if `obj` is a wrapper.
Parameters
----------
obj : object
Any object.
Returns
-------
res : bool
True if `obj` is a VTK wrapper. False, otherwise.
"""
return isinstance(obj, BSVTKObjectWrapper)