def run_standalone(self): from mayavi.core.engine import Engine from mayavi.plugins.script import Script from pyface.api import ApplicationWindow, GUI self.setup_logger() if self.offscreen: engine = Engine(scene_factory=off_screen_viewer) else: engine = Engine() engine.start() self.exception_info = None self.script = Script(engine=engine) self.gui = g = GUI() self.app_window = a = ApplicationWindow() a.open() a.show(False) g.invoke_later(self.run) g.start_event_loop() if self.exception_info is not None: type, value, tb = self.exception_info if sys.version_info[0] > 2: raise type(value).with_traceback(tb) else: raise type(value)
def setUp(self): ver = tvtk.Version() self.less_than_or_equal_to_vtk_5_10 = True if ver.vtk_major_version >= 5 and ver.vtk_minor_version > 10: self.less_than_or_equal_to_vtk_5_10 = False if self.less_than_or_equal_to_vtk_5_10: super(TestMlabPipeline, self).setUp() else: e = Engine() e.start() mlab.set_engine(e)
def setUp(self): ver = tvtk.Version() self.less_than_vtk_5_6 = True if ver.vtk_major_version >= 5 and ver.vtk_minor_version >= 10: self.less_than_vtk_5_6 = False if self.less_than_vtk_5_6: super(TestMlabPipeline, self).setUp() else: e = Engine() e.start() mlab.set_engine(e)
def run_standalone(self): from mayavi.core.engine import Engine from mayavi.plugins.script import Script from pyface.api import ApplicationWindow, GUI self.setup_logger() if self.offscreen: engine = Engine(scene_factory=off_screen_viewer) else: engine = Engine() engine.start() self.script = Script(engine=engine) self.gui = g = GUI() self.app_window = a = ApplicationWindow() a.open() a.show(False) g.invoke_later(self.run) g.start_event_loop()
def test_many_savefig_offscreen(self): """Test if savefig works with off_screen_rendering and Engine""" engine = Engine() for _ in range(5): self.setup_engine_and_figure(engine) # Use off-screen rendering self.figure.scene.off_screen_rendering = True # Set up the scene create_quiver3d() # save the figure savefig(self.filename, size=(131, 217), figure=self.figure)
def test_mlab_screenshot(self): # Given engine = Engine() self.setup_engine_and_figure(engine) create_quiver3d() sz = self.figure.scene.get_size() for aa in (False, True): # When data = screenshot(mode='rgb', antialiased=aa) # Then self.assertEqual(data.shape, (sz[1], sz[0], 3)) # When data = screenshot(mode='rgba', antialiased=aa) # Then self.assertEqual(data.shape, (sz[1], sz[0], 4))
def new_engine(self): """ Creates a new engine, envisage or not depending on the options. """ check_backend() if options.backend == 'envisage': from mayavi.plugins.app import Mayavi m = Mayavi(start_gui_event_loop=False) m.main() process_ui_events() window = m.application.workbench.active_window engine = window.get_service(Engine) elif options.backend == 'test': engine = NullEngine(name='Null Mlab Engine') engine.start() else: if options.offscreen: engine = OffScreenEngine(name='Mlab offscreen Engine') engine.start() else: engine = Engine(name='Mlab Engine') engine.start() self.current_engine = engine return engine
def create_fn(): e = Engine() e.start() return e
def main(): parser = argparse.ArgumentParser() parser.add_argument('filename', nargs='+', help='name of flydra .hdf5 file', ) parser.add_argument("--stim-xml", type=str, default=None, help="name of XML file with stimulus info", required=True, ) parser.add_argument("--align-json", type=str, default=None, help="previously exported json file containing s,R,T", ) parser.add_argument("--radius", type=float, help="radius of line (in meters)", default=0.002, metavar="RADIUS") parser.add_argument("--obj-only", type=str) parser.add_argument("--obj-filelist", type=str, help="use object ids from list in text file", ) parser.add_argument( "-r", "--reconstructor", dest="reconstructor_path", type=str, help=("calibration/reconstructor path (if not specified, " "defaults to FILE)")) args = parser.parse_args() options = args # optparse OptionParser backwards compatibility reconstructor_path = args.reconstructor_path fps = None ca = core_analysis.get_global_CachingAnalyzer() by_file = {} for h5_filename in args.filename: assert(tables.is_hdf5_file(h5_filename)) obj_ids, use_obj_ids, is_mat_file, data_file, extra = ca.initial_file_load( h5_filename) this_fps = result_utils.get_fps( data_file, fail_on_error=False ) if fps is None: if this_fps is not None: fps = this_fps if reconstructor_path is None: reconstructor_path = data_file by_file[h5_filename] = (use_obj_ids, data_file) del h5_filename del obj_ids, use_obj_ids, is_mat_file, data_file, extra if options.obj_only is not None: obj_only = core_analysis.parse_seq(options.obj_only) else: obj_only = None if reconstructor_path is None: raise RuntimeError('must specify reconstructor from CLI if not using .h5 files') R = reconstruct.Reconstructor(reconstructor_path) if fps is None: fps = 100.0 warnings.warn('Setting fps to default value of %f'%fps) else: fps = 1.0 if options.stim_xml is None: raise ValueError( 'stim_xml must be specified (how else will you align the data?') if 1: stim_xml = xml_stimulus.xml_stimulus_from_filename( options.stim_xml, ) try: fanout = xml_stimulus.xml_fanout_from_filename( options.stim_xml ) except xml_stimulus.WrongXMLTypeError: pass else: include_obj_ids, exclude_obj_ids = fanout.get_obj_ids_for_timestamp( timestamp_string=file_timestamp ) if include_obj_ids is not None: use_obj_ids = include_obj_ids if exclude_obj_ids is not None: use_obj_ids = list( set(use_obj_ids).difference( exclude_obj_ids ) ) print('using object ids specified in fanout .xml file') if stim_xml.has_reconstructor(): stim_xml.verify_reconstructor(R) x = [] y = [] z = [] speed = [] if options.obj_filelist is not None: obj_filelist=options.obj_filelist else: obj_filelist=None if obj_filelist is not None: obj_only = 1 if obj_only is not None: if len(by_file) != 1: raise RuntimeError("specifying obj_only can only be done for a single file") if obj_filelist is not None: data = np.loadtxt(obj_filelist,delimiter=',') obj_only = np.array(data[:,0], dtype='int') print(obj_only) use_obj_ids = numpy.array(obj_only) h5_filename = by_file.keys()[0] (prev_use_ob_ids, data_file) = by_file[h5_filename] by_file[h5_filename] = (use_obj_ids, data_file) for h5_filename in by_file: (use_obj_ids, data_file) = by_file[h5_filename] for obj_id_enum,obj_id in enumerate(use_obj_ids): rows = ca.load_data( obj_id, data_file, use_kalman_smoothing=False, #dynamic_model_name = dynamic_model_name, #frames_per_second=fps, #up_dir=up_dir, ) verts = numpy.array( [rows['x'], rows['y'], rows['z']] ).T if len(verts)>=3: verts_central_diff = verts[2:,:] - verts[:-2,:] dt = 1.0/fps vels = verts_central_diff/(2*dt) speeds = numpy.sqrt(numpy.sum(vels**2,axis=1)) # pad end points speeds = numpy.array([speeds[0]] + list(speeds) + [speeds[-1]]) else: speeds = numpy.zeros( (verts.shape[0],) ) if verts.shape[0] != len(speeds): raise ValueError('mismatch length of x data and speeds') x.append( verts[:,0] ) y.append( verts[:,1] ) z.append( verts[:,2] ) speed.append(speeds) data_file.close() del h5_filename, use_obj_ids, data_file if 0: # debug if stim_xml is not None: v = None for child in stim_xml.root: if child.tag == 'cubic_arena': info = stim_xml._get_info_for_cubic_arena(child) v=info['verts4x4'] if v is not None: for vi in v: print('adding',vi) x.append( [vi[0]] ) y.append( [vi[1]] ) z.append( [vi[2]] ) speed.append( [100.0] ) x = np.concatenate(x) y = np.concatenate(y) z = np.concatenate(z) w = np.ones_like(x) speed = np.concatenate(speed) # homogeneous coords verts = np.array([x,y,z,w]) ####################################################### # Create the MayaVi engine and start it. e = Engine() # start does nothing much but useful if someone is listening to # your engine. e.start() # Create a new scene. from tvtk.tools import ivtk #viewer = ivtk.IVTK(size=(600,600)) viewer = IVTKWithCalGUI(size=(800,600)) viewer.open() e.new_scene(viewer) viewer.cal_align.set_data(verts,speed,R,args.align_json) if 0: # Do this if you need to see the MayaVi tree view UI. ev = EngineView(engine=e) ui = ev.edit_traits() # view aligned data e.add_source(viewer.cal_align.source) v = Vectors() v.glyph.scale_mode = 'data_scaling_off' v.glyph.color_mode = 'color_by_scalar' v.glyph.glyph_source.glyph_position='center' v.glyph.glyph_source.glyph_source = tvtk.SphereSource( radius=options.radius, ) e.add_module(v) if stim_xml is not None: if 0: stim_xml.draw_in_mayavi_scene(e) else: actors = stim_xml.get_tvtk_actors() viewer.scene.add_actors(actors) gui = GUI() gui.start_event_loop()
def setUp(self): e = Engine() e.start() self._non_null_engine = e mlab.set_engine(e)
def setUp(self): e = Engine() e.start() mlab.set_engine(e)
def __engine_default(self): e = Engine() e.start() e.new_scene(self._scene) return e