def add_dataset(dataset, name='', **kwargs): """Add a dataset object to the Mayavi pipeline. **Parameters** :dataset: a tvtk dataset, or a Mayavi source. The dataset added to the Mayavi pipeline :figure: a figure identifier number or string, None or False, optionnal. If no `figure` keyword argument is given, the data is added to the current figure (a new figure if created if necessary). If a `figure` keyword argument is given, it should either the name the number of the figure the dataset should be added to, or None, in which case the data is not added to the pipeline. If figure is False, a null engine is created. This null engine does not create figures, and is mainly usefull for tensting, or using the VTK algorithms without visualization. **Returns** The corresponding Mayavi source is returned. """ if isinstance(dataset, tvtk.Object): d = VTKDataSource() d.data = dataset elif isinstance(dataset, Source): d = dataset else: raise TypeError, \ "first argument should be either a TVTK object"\ " or a mayavi source" if len(name) > 0: d.name = name if not 'figure' in kwargs: # No figure has been specified, retrieve the default one. gcf() engine = get_engine() elif kwargs['figure'] is False: # Get a null engine that we can use. engine = get_null_engine() elif kwargs['figure'] is not None: figure = kwargs['figure'] engine = engine_manager.find_figure_engine(figure) engine.current_scene = figure else: # Return early, as we don't want to add the source to an engine. return d engine.add_source(d) return d
def _find_module_manager(object=None, data_type=None): """If an object is specified, returns its module_manager, elsewhere finds the first module_manager in the scene. """ if object is None: for object in _traverse(gcf()): if isinstance(object, ModuleManager): if data_type == 'scalar': if not _has_scalar_data(object): continue try: if not object.actor.mapper.scalar_visibility: continue except AttributeError: pass if data_type == 'vector' and not _has_vector_data(object): continue if data_type == 'tensor' and not _has_tensor_data(object): continue return object else: if hasattr(object, 'module_manager'): if ((data_type == 'scalar' and _has_scalar_data(object)) or (data_type == 'vector' and _has_vector_data(object)) or (data_type == 'tensor' and _has_tensor_data(object)) or data_type is None): return object.module_manager else: print("This object has no %s data" % data_type) else: print("This object has no color map") return None
def __init__(self, *args, **kwargs): """ Try to find an module actor with the same name, on the given parent (if any) and use it rather than building a new module.""" # Call the HasTraits constructor, but not the PipeBase one. HasTraits.__init__(self) self._scene = gcf() if not 'figure' in kwargs: self._engine = get_engine() else: figure = kwargs['figure'] self._engine = engine_manager.find_figure_engine(figure) self._engine.current_scene = figure kwargs.pop('figure') if self._scene.scene is not None: self._scene.scene.disable_render = True # Process the arguments if len(args)==1: (parent, ) = args elif len(args)==0: parent = self._engine.current_object else: raise ValueError, "Wrong number of arguments" # Try to find an existing module, if not add one to the pipeline if parent == None: target = self._scene else: target = parent klass = self._target.__class__ for obj in tools._traverse(target): if ( isinstance(obj, klass) and obj.name == self.name ): self._target = obj break else: # Keep a reference to the parent self._parent = parent self._engine.add_module(self._target, obj=parent) # Now calling the traits setter, so that traits handlers are # called self.set(**kwargs) if self._scene.scene is not None: self._scene.scene.disable_render = False
def __init__(self, *args, **kwargs): """ Try to find an module actor with the same name, on the given parent (if any) and use it rather than building a new module.""" # Call the HasTraits constructor, but not the PipeBase one. HasTraits.__init__(self) self._scene = gcf() if not 'figure' in kwargs: self._engine = get_engine() else: figure = kwargs['figure'] self._engine = engine_manager.find_figure_engine(figure) self._engine.current_scene = figure kwargs.pop('figure') if self._scene.scene is not None: self._scene.scene.disable_render = True # Process the arguments if len(args) == 1: (parent, ) = args elif len(args) == 0: parent = self._engine.current_object else: raise ValueError("Wrong number of arguments") # Try to find an existing module, if not add one to the pipeline if parent == None: target = self._scene else: target = parent klass = self._target.__class__ for obj in tools._traverse(target): if (isinstance(obj, klass) and obj.name == self.name): self._target = obj break else: # Keep a reference to the parent self._parent = parent self._engine.add_module(self._target, obj=parent) # Now calling the traits setter, so that traits handlers are # called self.set(**kwargs) if self._scene.scene is not None: self._scene.scene.disable_render = False