def add_module(self, module): """ Adds a module smartly. If no ModuleManager instances are children, it first creates a new ModuleManager and then adds the module to it. If not it adds the module to the first available ModuleManager instance.""" mm = None for child in self.children: if isinstance(child, ModuleManager): mm = child if mm is None: mm = ModuleManager(source=self, scene=self.scene) if self.running: mm.start() self.children.append(mm) if self.recorder is not None: index = len(self.children) - 1 self.recorder.register(mm, parent=self, trait_name_on_parent='children[%d]' % index) mm.children.append(module)
def process_cmd_line(app, opts, args): """ Processes the passed command line arguments. Input Arguments: app -- A Mayavi application instance. opts -- The list of options returned by getopt. args -- The remaining arguments returned by getopt. """ from mayavi.core.common import error, exception from tvtk.common import camel2enthought sources = _get_non_file_sources() script = app.script last_obj = None # Start a new scene by default if there is none currently and none # was specified at the start of the command line arguments. if script.engine.current_scene is None: new_scene = False if len(opts) == 0: if len(args) == 0: new_scene = True elif (opts[0][0] not in ('-n', '--new-scene', '-z', '--visualization', '--viz', '-x', '--exec')): new_scene = True if new_scene: last_obj = script.new_scene() for o, a in opts: if o in ('-d', '--data'): base, ext = splitext(a) if exists(a): last_obj = script.open(a) elif a in sources: md = sources[a] src = md.get_callable()() script.add_source(src) last_obj = src else: error("File/Source %s does not exist!" % a) return if o in ('-m', '--module'): if '.' in a: idx = a.rfind('.') modname = a[:idx] classname = a[idx+1:] else: modname = 'mayavi.modules.%s' % camel2enthought(a) classname = a try: mod = __import__(modname, globals(), locals(), [classname]) except ImportError as msg: exception(str(msg)) return else: m = getattr(mod, classname)() if classname == 'Labels': m.object = script.engine.current_object script.add_module(m) last_obj = m if o in ('-f', '--filter'): if '.' in a: idx = a.rfind('.') modname = a[:idx] classname = a[idx+1:] else: if a[:12] == 'UserDefined:': modname = 'mayavi.filters.user_defined' classname = 'UserDefined' # Create the wrapped filter. fname = a[12:] from tvtk.api import tvtk try: extra = getattr(tvtk, fname)() except (AttributeError, TypeError): # Don't worry about errors. extra = None else: modname = 'mayavi.filters.%s' % camel2enthought(a) classname = a extra = None try: mod = __import__(modname, globals(), locals(), [classname]) except ImportError as msg: exception(str(msg)) return else: klass = getattr(mod, classname) if classname != 'UserDefined': f = klass() else: if extra is not None: f = klass(filter=extra) else: f = klass() f.setup_filter() script.add_filter(f) last_obj = f if o in ('-M', '--module-mgr'): from mayavi.core.module_manager \ import ModuleManager mm = ModuleManager() script.add_filter(mm) last_obj = mm if o in ('-n', '--new-scene'): script.new_scene() e = script.engine s = e.scenes[-1] e.trait_set(current_scene=s, current_object=s) last_obj = s if o in ('-x', '--exec'): err = run_script(script, a) if err: # stop processing options. return if o in ('-s', '--set'): try: stmt = 'last_obj.' + a exec(stmt, locals(), globals()) except Exception as msg: exception(str(msg)) if o in ('-z', '--visualization', '--viz'): script.load_visualization(a) # for remaining arguments simply load saved visualizations. for arg in args: base, ext = splitext(arg) if ext == '.mv2': script.load_visualization(arg) elif ext == '.py': err = run_script(script, arg) if err: # stop processing arguments. return else: script.open(arg)
def add_module_manager(object): """ Add a module-manager, to control colors and legend bars to the given object. """ return get_engine().add_module(ModuleManager(), object)
klass = getattr(mod, classname) if classname != 'UserDefined': f = klass() else: if extra is not None: f = klass(filter=extra) else: f = klass() f.setup_filter() script.add_filter(f) last_obj = f if o in ('-M', '--module-mgr'): from mayavi.core.module_manager \ import ModuleManager mm = ModuleManager() script.add_filter(mm) last_obj = mm if o in ('-n', '--new-scene'): script.new_scene() e = script.engine s = e.scenes[-1] e.set(current_scene=s, current_object=s) last_obj = s if o in ('-x', '--exec'): err = run_script(script, a) if err: # stop processing options. return
image_plane_widget.ipw.point1 = array([1., 128.5, 0.5]) image_plane_widget.ipw.point2 = array([1., 0.5, 128.5]) scene.scene.show_axes = True scene.scene.camera.position = [ 486.97762996578587, 32.807552030816318, 127.31721271939678 ] scene.scene.camera.focal_point = [64.5, 64.5, 64.5] scene.scene.camera.view_angle = 30.0 scene.scene.camera.view_up = [ -0.16242997732460931, -0.57282261680926339, 0.80342439105252128 ] scene.scene.camera.clipping_range = [270.27987283787792, 628.23960958969758] scene.scene.camera.compute_view_plane_normal() scene.scene.render() from mayavi.core.module_manager import ModuleManager module_manager3 = ModuleManager() engine.add_module(module_manager3, obj=None) module_manager3.scalar_lut_manager.reverse_lut = True module_manager3.scalar_lut_manager.reverse_lut = False module_manager3.scalar_lut_manager.reverse_lut = True module_manager3.scalar_lut_manager.reverse_lut = False array_source2 = engine.scenes[0].children[2] array_source2.children[1:2] = [] module_manager4 = ModuleManager() engine.add_module(module_manager4, obj=None) array_source = engine.scenes[0].children[0] array_source.children[1:2] = [] from mayavi.modules.axes import Axes axes = Axes() module_manager = engine.scenes[0].children[0].children[0]