def addmodules(self, idx, addTextIndexer): #add Outline module o = Outline() mayavi.add_module(o) #add OrientationAxes module oa = OrientationAxes() mayavi.add_module(oa) """ #add IsoSurface module if requested i = IsoSurface() mayavi.add_module(i) """ #add Surface module if requested s = Surface() s.enable_contours = True s.actor.property.opacity = 0.5 mayavi.add_module(s) #add Text module if requested t1 = Text() t1.text = self.title t1.actor.scaled_text = False t1.actor.text_property.font_size = 18 mayavi.add_module(t1) t1.width = 1.0 * t1.actor.mapper.get_width( t1.scene.renderer) / t1.scene.renderer.size[0] height = 1.0 * t1.actor.mapper.get_height( t1.scene.renderer) / t1.scene.renderer.size[1] t1.x_position = 0.5 - t1.width / 2 t1.y_position = 1 - height if (addTextIndexer): #add default Text module for indicating scene index self.sceneTextCount = Text() self.sceneTextCount.text = "0" mayavi.add_module(self.sceneTextCount) self.sceneTextCount.actor.scaled_text = False self.sceneTextCount.actor.text_property.font_size = 24 self.sceneTextCount.x_position = .95 self.sceneTextCount.y_position = .05
def test_script_recording(self): "Does script recording work correctly." # Create a mayavi pipeline and record it. tape = self.tape e = NullEngine() e.start() # Start recording. tape.recording = True tape.register(e, known=True, script_id="engine") e.new_scene() # print tape.script self.assertEqual(tape.lines[-1], "dummy_viewer = engine.new_scene()") src = ParametricSurface() e.add_source(src) expect = "from enthought.mayavi.sources.parametric_surface " "import ParametricSurface" self.assertEqual(tape.lines[-3], expect) self.assertEqual(tape.lines[-2], "parametric_surface = ParametricSurface()") self.assertEqual(tape.lines[-1], "engine.add_source(parametric_surface)") src.function = "dini" self.assertEqual(tape.lines[-1], "parametric_surface.function = 'dini'") o = Outline() e.add_module(o) expect = "from enthought.mayavi.modules.outline import Outline" self.assertEqual(tape.lines[-3], expect) self.assertEqual(tape.lines[-2], "outline = Outline()") self.assertEqual(tape.lines[-1], "engine.add_module(outline)") o.actor.property.color = (1, 0, 0) self.assertEqual(tape.lines[-1], "outline.actor.property.color = (1.0, 0.0, 0.0)") s = Surface() e.add_module(s) expect = "from enthought.mayavi.modules.surface import Surface" self.assertEqual(tape.lines[-3], expect) self.assertEqual(tape.lines[-2], "surface = Surface()") self.assertEqual(tape.lines[-1], "engine.add_module(surface)") s.actor.property.representation = "wireframe" self.assertEqual(tape.lines[-1], "surface.actor.property.representation = 'wireframe'") o.actor.property.representation = "wireframe" self.assertEqual(tape.lines[-1], "outline.actor.property.representation = 'wireframe'") s.actor.property.opacity = 0.5 self.assertEqual(tape.lines[-1], "surface.actor.property.opacity = 0.5") s.actor.mapper.scalar_visibility = False self.assertEqual(tape.lines[-1], "surface.actor.mapper.scalar_visibility = False") # print tape.script # Stop recording and test. tape.unregister(e) tape.record("#end") # Placeholder o.actor.property.opacity = 0.5 self.assertEqual(tape.lines[-1], "#end") s.actor.property.color = (1, 0, 0) self.assertEqual(tape.lines[-1], "#end") s.enable_contours = True self.assertEqual(tape.lines[-1], "#end") src.function = "klein" self.assertEqual(tape.lines[-1], "#end")
eug1.filter.cell_maximum = 345966 s = Surface() eug1.add_module(s) s.actor.mapper.scalar_visibility = True # scalar field on the surface ### for the dielectric parallellepiped script.engine.current_object = src eug2 = ExtractUnstructuredGrid() script.add_filter(eug2) eug2.filter.cell_clipping = True eug2.filter.cell_minimum = 345967 eug2.filter.cell_maximum = 349094 s = Surface() eug2.add_module(s) s.actor.mapper.scalar_visibility = True # scalar field set to on s.enable_contours = True # in the volume ### we need also extract the required cells for and only for the vaccum script.engine.current_object = src # current object must be set to the source eug3 = ExtractUnstructuredGrid() script.add_filter(eug3) eug3.filter.cell_clipping = True eug3.filter.cell_minimum = 0 eug3.filter.cell_maximum = 342880 ... / ... # <markdowncell> # This should render this: #
# Using Surface module is straightforward: # # <codecell> from enthought.mayavi.modules.surface import Surface # <markdowncell> # then # # <codecell> s = Surface() s.enable_contours = True # we want contours enabled s.contour.auto_contours = True # we want isovalues automatically well-defined s.contour.number_of_contours = 10 # self-explanatory ;-) s.actor.property.opacity = 0.2 script.add_module(s) s.contour.minimum_contour = 0 s.contour.maximum_contour = 1 s.module_manager.scalar_lut_manager.data_range = [0, 1] # <markdowncell> # The scene should look like this: # # ![](files/MayaVi(2f)ScriptingMayavi2(2f)MainModules_attachments/module_surface.png # # Using the !IsoSurface module is not more difficult. As an example, say
# isosurfaces. # # Using Surface module is straightforward: # # <codecell> from enthought.mayavi.modules.surface import Surface # <markdowncell> # then # # <codecell> s = Surface() s.enable_contours = True # we want contours enabled s.contour.auto_contours = True # we want isovalues automatically well-defined s.contour.number_of_contours = 10 # self-explanatory ;-) s.actor.property.opacity = 0.2 script.add_module(s) s.contour.minimum_contour = 0 s.contour.maximum_contour = 1 s.module_manager.scalar_lut_manager.data_range = [0, 1] # <markdowncell> # The scene should look like this: # # ![](files/MayaVi(2f)ScriptingMayavi2(2f)MainModules_attachments/module_surface.png # # Using the !IsoSurface module is not more difficult. As an example, say
eug1.filter.cell_maximum = 345966 s = Surface() eug1.add_module(s) s.actor.mapper.scalar_visibility = True # scalar field on the surface ### for the dielectric parallellepiped script.engine.current_object = src eug2 = ExtractUnstructuredGrid() script.add_filter(eug2) eug2.filter.cell_clipping = True eug2.filter.cell_minimum = 345967 eug2.filter.cell_maximum = 349094 s = Surface() eug2.add_module(s) s.actor.mapper.scalar_visibility = True # scalar field set to on s.enable_contours = True # in the volume ### we need also extract the required cells for and only for the vaccum script.engine.current_object = src # current object must be set to the source eug3 = ExtractUnstructuredGrid() script.add_filter(eug3) eug3.filter.cell_clipping = True eug3.filter.cell_minimum = 0 eug3.filter.cell_maximum = 342880 .../... # <markdowncell> # This should render this: #