Exemplo n.º 1
0
    def __init__(self, width, height, n_rows, n_columns):
        HasTraits.__init__(self)

        n_scenes = n_rows * n_columns
        if n_scenes < 1:
            raise ValueError("n_rows=%r, n_columns=%r" % (n_rows, n_columns))

        self.scenes = tuple(MlabSceneModel() for _ in xrange(n_scenes))
        for i, scene in enumerate(self.scenes):
            self.add_trait(SCENE_NAME % i, scene)

        if n_rows == n_columns == 1:
            self.view = View(Item(SCENE_NAME % 0,
                                  editor=SceneEditor(scene_class=Scene),
                                  resizable=True,
                                  show_label=False),
                             width=width,
                             height=height,
                             resizable=True)
        else:
            rows = []
            for row in xrange(n_rows):
                columns = []
                for column in xrange(n_columns):
                    i = row * n_columns + column
                    item = Item(SCENE_NAME % i,
                                editor=SceneEditor(scene_class=Scene),
                                resizable=True,
                                show_label=False)
                    columns.append(item)
                rows.append(HGroup(*columns))
            self.view = View(VGroup(*rows))

        self.figures = [scene.mayavi_scene for scene in self.scenes]
Exemplo n.º 2
0
class MyDialog(HasTraits):

    scene1 = Instance(MlabSceneModel, ())
    scene2 = Instance(MlabSceneModel, ())

    # print( scene1 )
    #     scene1.mayavi_scene.on_mouse_pick( lambda x : print( '5' ) )

    button1 = Button('Redraw')
    button2 = Button('Redraw')

    @on_trait_change('button1')
    def redraw_scene1(self):
        self.redraw_scene(self.scene1)

    @on_trait_change('button2')
    def redraw_scene2(self):
        self.redraw_scene(self.scene2)

    def redraw_scene(self, scene):
        # Notice how each mlab call points explicitely to the figure it
        # applies to.
        mlab.clf(figure=scene.mayavi_scene)
        x, y, z, s = np.random.random((4, 100))
        mlab.points3d(x, y, z, s, figure=scene.mayavi_scene)

    # The layout of the dialog created
    view = View(
        HSplit(
            Group(
                Item('scene1', editor=SceneEditor(), height=250, width=300),
                'button1',
                show_labels=False,
            ),
            Group(
                Item('scene2',
                     editor=SceneEditor(),
                     height=250,
                     width=300,
                     show_label=False),
                'button2',
                show_labels=False,
            ),
        ),
        resizable=True,
    )

    def mouseReleaseEvent(self, QMouseEvent):
        if QMouseEvent.button() == QtCore.Qt.LeftButton:
            print("Left Button Clicked")
        elif QMouseEvent.button() == QtCore.Qt.RightButton:
            #do what you want here
            print("Right Button Clicked")
Exemplo n.º 3
0
 def default_traits_view(self):
     return View(
         HGroup(
             Group(
                 Label('Data'),
                 Item('y_selected', show_label=False),
                 Item('_'),
                 Label('Cut planes'),
                 Item('cuts', style='custom', show_label=False),
                 Item('_'),
                 Label('ISO Surfaces'),
                 Item('level_surface', show_label=False),
                 Item('_'),
                 Label('Colormap'),
                 #                     Item('lut_scale', show_label=False),
                 Item('lut_mode', show_label=False),
                 Item('reverse_lut', style='custom', show_label=False),
                 Item('min_is_best', style='custom', show_label=False),
                 Label('zoom color'),
                 Item('lut_range', show_label=False),
                 Item('_'),
                 Spring()),
             Item('scene',
                  editor=SceneEditor(scene_class=MayaviScene),
                  show_label=False),
         ),
         #             Group( ['_'] + self.param_names ),
         resizable=True)
Exemplo n.º 4
0
class ODEPlot3D(HasTraits):
    """ A 2D plot of ode solution variables. """
    scene = Instance(MlabSceneModel, args=())
    plot3d = Any
    ode = Property(Instance(ODE), depends_on='solver')
    solver = Instance(ODESolver)
    traits_view = View(Item('scene',
                            editor=SceneEditor(scene_class=MayaviScene),
                            show_label=False),
                       width=800,
                       height=700,
                       resizable=True,
                       title="ODE Solution")

    def _get_ode(self):
        return self.solver and self.solver.ode

    @on_trait_change('solver.solution')
    def _on_solution_changed(self):
        # TODO: an exercise for the reader
        pass

    @on_trait_change('scene.activated')
    def update_flow(self):
        self.plot3d = self.scene.mlab.plot3d(self.solver.solution[:, 0],
                                             self.solver.solution[:, 1],
                                             self.solver.solution[:, 2],
                                             self.solver.t,
                                             tube_radius=0.1)
Exemplo n.º 5
0
class MlabVisualization(HasTraits):
    """I don't really understand this class, it was stolen from an example for qt-embedded mayavi"""
    scene = Instance(MlabSceneModel, ())

    view = View(Item('scene', editor=SceneEditor(scene_class=MayaviScene),
                     height=600, width=600, show_label=False),
                resizable=True)
Exemplo n.º 6
0
class LTPAResults(HasTraits):
    scene3d_inited = Bool(False)
    results = List(Instance(LTPAResult))
    scene3d = Instance(MlabSceneModel, (), transient=True)

    def __init__(self, **traits):
        super(LTPAResults, self).__init__(**traits)
        for res in self.results:
            res.scene3d = self.scene3d

    traits_view = View(
        Group(Item("results", editor=ltpa_result_table), show_labels=False))
    test_view = View(Group(Item("scene3d",
                                editor=SceneEditor(scene_class=Scene),
                                height=500,
                                width=500),
                           Item("results", editor=ltpa_result_table),
                           show_labels=False),
                     resizable=True)

    @on_trait_change('scene3d.activated')
    def display_scene3d(self):
        if self.scene3d_inited: return
        for res in self.results:
            res.visible = True
class MayaviExample(HasTraits):
    n_balls = Range(1, 400, 50, mode='spinner')  # )
    black_balls = Bool(True)


    view = View(Item('scene', editor=SceneEditor(scene_class=MayaviScene),
                     height=450, width=500, show_label=False),
                Group('_', 'n_balls', 'black_balls', orientation='horizontal'),
                resizable=True,  # We need this to resize with the parent widget
                )

    scene = Instance(MlabSceneModel, ())

    def __init__(self,):
        super().__init__()

    @on_trait_change('scene.activated,n_balls,black_balls')
    def update_plot(self, *args, **kwargs):
        # We can do normal mlab calls on the embedded scene.
        self.scene.mlab.clf(figure=self.scene.mayavi_scene)
        data = np.random.randn(self.n_balls, 3)
        if self.black_balls:
            color = (0.3,0.3,0.3)
        else:
            color = (1,0,0)
        pts = self.scene.mlab.points3d(data[:,0],data[:,1],data[:,2], figure=self.scene.mayavi_scene,color=color)
Exemplo n.º 8
0
class MultiDimPanel(HasTraits):
    scene = Instance(MlabSceneModel, ())

    # The layout of the panel created by Traits
    view = View(Item('scene',
                     editor=SceneEditor(),
                     resizable=True,
                     show_label=False),
                resizable=True)

    def __init__(self, parent):
        HasTraits.__init__(self)
        # Create some data, and plot it using the embedded scene's engine

        self.parent = parent
        pub.subscribe(self.on_patient_loaded, "patient.loaded")
        pub.subscribe(self.voi_changed, "voi.selection_changed")

    def Init(self):
        pass

    def on_patient_loaded(self, msg):
        self.data = msg.data
        ct_data = self.data.voxelplan_images
        x, y, z = ogrid[0:1:ct_data.dimx, 0:1:ct_data.dimy, 0:1:ct_data.dimz]
        src = ArraySource(scalar_data=ct_data.cube)
        self.scene.engine.add_source(src)
        src.add_module(IsoSurface())

    def voi_changed(self, msg):
        pass
Exemplo n.º 9
0
class MyModel(HasTraits):
    n_meridional = Range(0, 30, 6)
    n_longitudinal = Range(0, 30, 11)
    # 场景模型实例
    scene = Instance(MlabSceneModel, ())
    # 管线实例
    plot = Instance(PipelineBase)
    #当场景被激活,或者参数发生改变,更新图形
    @on_trait_change('n_meridional,n_longitudinal,scene.activated')
    def update_plot(self):
        x, y, z, t = curve(self.n_meridional, self.n_longitudinal)
        if self.plot is None:  #如果plot未绘制则生成plot3d
            self.plot = self.scene.mlab.plot3d(x,
                                               y,
                                               z,
                                               t,
                                               tube_radius=0.025,
                                               colormap='Spectral')
        else:  #如果数据有变化,将数据更新即重新赋值
            self.plot.mlab_source.set(x=x, y=y, z=z, scalars=t)

    # 建立视图布局
    view = View(
        Item('scene',
             editor=SceneEditor(scene_class=MayaviScene),
             height=250,
             width=300,
             show_label=False),  #图形窗口界面
        Group('_', 'n_meridional', 'n_longitudinal'),  #滑动条
        resizable=True)
class TestModel(HasTraits):
	scene = Instance(MlabSceneModel, ())
	plot = Instance(PipelineBase)
	print 'life is pain'
	t=int(0)
	s=1000

	#self.scene.mlab.points3D(testData[:,0,t]*s,testData[:,1,t]*s,testData[:,2,t]*s,'ob')
	@on_trait_change('t')
	def update_plot(self):
		if self.plot is None:
			print 'FIRST PLOT'
			self.plot=self.scene.mlab.points3D(testData[:,0,t]*s,testData[:,1,t]*s,testData[:,2,t]*s,'ob')
		else:
			print 'T has changed to:',t
			self.plot=self.scene.mlab.points3D(testData[:,0,t]*s,testData[:,1,t]*s,testData[:,2,t]*s,'rb')
	
	#@on_trait_change('t')
	#def update_plot(self):
	#	if self.plot is None:
	#		print 'FIRST PLOT'
	#		self.plot=self.scene.mlab.points3D(testData[:,0,t]*s,testData[:,1,t]*s,testData[:,2,t]*s,'ob')
	#	else:
	#		print 'T has changed to:',t
	#		self.plot=self.scene.mlab.points3D(testData[:,0,t]*s,testData[:,1,t]*s,testData[:,2,t]*s,'rb')

	view=View(Item('scene',editor=SceneEditor(scene_class=MayaviScene),height=1000,width=2000,show_label=False),Group('_','t'),resizable=True,)
Exemplo n.º 11
0
class Visualization(HasTraits):
    scene = Instance(MlabSceneModel, ())

    @on_trait_change('scene.activated')
    def update_plot(self):
        # This function is called when the view is opened. We don't
        # populate the scene when the view is not yet open, as some
        # VTK features require a GLContext.

        # We can do normal mlab calls on the embedded scene.
        self.scene.mlab.clf()
        if type(self.data) is list:
            for idata in self.data:
                maskedarray = np.ma.masked_invalid(idata[2])
                self.scene.mlab.surf(maskedarray, colormap = 'jet',warp_scale='auto', mask = maskedarray.mask)
        elif type(self.data) is np.ndarray and self.data.shape[1] == 4:
            self.scene.mlab.points3d(self.data[:,0], self.data[:,1], self.data[:,2],self.data[:,3] + 2, colormap = 'jet')

    def setData(self, data):
        self.data = data
    # the layout of the dialog screated
    view = View(Item('scene', editor=SceneEditor(scene_class=MayaviScene),
                     height=250, width=400, show_label=False),
                resizable=True # We need this to resize with the parent widget
                )
Exemplo n.º 12
0
class MyModel(HasTraits):
    n_meridional = Range(0, 30, 6)
    n_longitudinal = Range(0, 30, 11)
    n_tube_radius = Range(0.01, 0.04, 0.025)
    s_colormap = Str('Spectral')
    background_color = Color(0x7B7B7B)
    s_representation = Str('surface')
    #    points,wireframe,surface

    # 场景模型实例
    scene = Instance(MlabSceneModel, ())
    # 管线实例
    plot = Instance(PipelineBase)
    #当场景被激活,或者参数发生改变,更新图形
    @on_trait_change(
        'n_meridional,n_longitudinal,n_tube_radius,s_colormap,background_color,s_representation,scene.activated'
    )
    def update_plot(self):
        x, y, z, t = curve(self.n_meridional, self.n_longitudinal)
        if self.plot is None:  #如果plot未绘制则生成plot3d
            self.plot = self.scene.mlab.plot3d(x,
                                               y,
                                               z,
                                               t,
                                               tube_radius=self.n_tube_radius,
                                               colormap=self.s_colormap)

        else:  #如果数据有变化,将数据更新即重新赋值
            self.plot.mlab_source.set(x=x,
                                      y=y,
                                      z=z,
                                      scalars=t,
                                      colormap=self.s_colormap)

            s = mlab.gcf()
            #设置scens 的背景色
            s.scene.background = self.background_color.getRgbF()[0:3]

            #设置colormap
            module_manager = s.children[0].children[0].children[0].children[
                0]  #获得所属对象
            module_manager.scalar_lut_manager.lut_mode = self.s_colormap

            #设置表现方式
            surface = module_manager.children[0]  #在module_manager获得下级所属对象
            surface.actor.property.representation = self.s_representation


# 建立视图布局

    view = View(Item('scene',
                     editor=SceneEditor(scene_class=MayaviScene),
                     height=250,
                     width=300,
                     show_label=False),
                Group('_', 'n_meridional', 'n_longitudinal',
                      'background_color', 's_colormap', 's_representation'),
                resizable=True,
                title="hongjy1 test")
Exemplo n.º 13
0
class MyApp(HasTraits):

    # The first engine. As default arguments (an empty tuple) are given,
    # traits initializes it.
    engine1 = Instance(Engine, args=())

    scene1 = Instance(MlabSceneModel)

    def _scene1_default(self):
        " The default initializer for 'scene1' "
        self.engine1.start()
        scene1 = MlabSceneModel(engine=self.engine1)
        return scene1

    engine2 = Instance(Engine, ())

    scene2 = Instance(MlabSceneModel)

    def _scene2_default(self):
        " The default initializer for 'scene2' "
        self.engine2.start()
        scene2 = MlabSceneModel(engine=self.engine2)
        return scene2

    # We populate the scenes only when it is activated, to avoid problems
    # with VTK objects that expect an active scene
    @on_trait_change('scene1.activated')
    def populate_scene1(self):
        self.scene1.mlab.test_surf()

    @on_trait_change('scene2.activated')
    def populate_scene2(self):
        self.scene2.mlab.test_mesh()

    # The layout of the view
    view = View(Group(
        Item('scene1',
             editor=SceneEditor(scene_class=MayaviScene),
             width=480,
             height=480)),
                Group(
                    Item('scene2',
                         editor=SceneEditor(scene_class=MayaviScene),
                         width=480,
                         height=480)),
                resizable=True)
Exemplo n.º 14
0
class MyDialog(HasTraits):

    scene = Instance(MlabSceneModel, ())

    # The parameters for the Lorenz system, defaults to the standard ones.
    x = Range(0, 32, 16, desc='pixel coord x', enter_set=True,
              auto_set=False)
    y = Range(0, 32, 16, desc='pixel coord y', enter_set=True,
              auto_set=False)

    # Tuple of x, y, z arrays where the field is sampled.
    points = Tuple(Array, Array, Array)

    # The layout of the dialog created
    view = View(
        VSplit(
            Item('scene',
                 editor=SceneEditor(), height=250,
                 width=300),
            'x',
            'y',
            show_labels=False,
          ),
        resizable=True,
    )

    def __init__(self):
        # Do not forget to call the parent's __init__
        HasTraits.__init__(self)
        
        data = sio.loadmat('img6')
        self.H = data['H2'].T
        
    @on_trait_change('scene.activated')
    def update_cone(self):
        mlab.clf(figure=self.scene.mayavi_scene)
        y, x, z = self.points
        img = np.zeros((sensor_res, sensor_res))
        img[self.y, self.x] = 1
        cone = self.H * img.reshape((-1, 1))
        self.src = mlab.pipeline.scalar_field(y, x, z, cone.reshape(y.shape), figure=self.scene.mayavi_scene)
        ipw_x = mlab.pipeline.image_plane_widget(self.src, plane_orientation='x_axes', figure=self.scene.mayavi_scene)
        ipw_y = mlab.pipeline.image_plane_widget(self.src, plane_orientation='y_axes', figure=self.scene.mayavi_scene)
        ipw_z = mlab.pipeline.image_plane_widget(self.src, plane_orientation='z_axes', figure=self.scene.mayavi_scene)
        mlab.colorbar()
        mlab.axes()
        
    @on_trait_change('x, y')
    def update_img(self):
        y, x, z = self.points
        img = np.zeros((sensor_res, sensor_res))
        img[self.y, self.x] = 1
        cone = self.H * img.reshape((-1, 1))
        self.src.mlab_source.scalars = cone.reshape(y.shape)
        
    def _points_default(self):
        y, x, z = np.mgrid[0:10:0.1, 0:10:0.1, 0:10:0.1]
        return y, x, z
Exemplo n.º 15
0
        class Visualization(HasTraits):

            scene = Instance(MlabSceneModel, ())
            view = View(Item('scene',
                             width=width,
                             height=height,
                             show_label=False,
                             editor=SceneEditor(scene_class=MayaviScene)),
                        resizable=True)
Exemplo n.º 16
0
 def __init__(self, items=None):
     self.fig = Instance(MlabSceneModel, ())
     self.view = View(Group(Item('scene1',
                                 editor=SceneEditor(),
                                 height=250,
                                 width=300),
                            'button1',
                            show_labels=False),
                      resizable=True)
class DemoApp(HasTraits):
    n_meridional = Range(0, 30, 6)
    n_longitudinal = Range(0, 30, 11)
    plotbutton = Button(u"绘图")
    # 场景模型实例
    scene = Instance(MlabSceneModel, ())
    #当场景被激活,或者参数发生改变,更新图形
    @on_trait_change('n_meridional,n_longitudinal,scene.activated')
    def update_plot(self):
        x, y, z, t = curve(self.n_meridional, self.n_longitudinal)
        if self.plot is None:  #如果plot未绘制则生成plot3d
            self.plot = self.scene.mlab.plot3d(x,
                                               y,
                                               z,
                                               t,
                                               tube_radius=0.025,
                                               colormap='Spectral')
        else:  #如果数据有变化,将数据更新即重新赋值
            self.plot.mlab_source.set(x=x, y=y, z=z, scalars=t)

    #建立视图
    view = View(
        Item('scene',
             editor=SceneEditor(scene_class=MayaviScene),
             height=250,
             width=300,
             show_label=False),  #图形窗口界面
        Group('_',
              'n_meridional',
              'n_longitudinal',
              Item('model_name', label=u'模型名称'),
              Item('model_file', label=u'文件名'),
              Item('category', label=u'模型类型'),
              'plotbutton',
              show_border=True),
        title='view_range_text',
        buttons=['OK'],
        resizable=True,  #可变窗口大小
    )

    def _plotbutton_fired(self):
        self.plot()

    def plot(self):
        # 管线实例,初始化函数
        plot = Instance(PipelineBase)
        x, y, z, t = curve(self.n_meridional, self.n_longitudinal)
        self.plot = self.scene.mlab.plot3d(x,
                                           y,
                                           z,
                                           t,
                                           tube_radius=0.025,
                                           colormap='Spectral')

    model_name = Str
    category = Str
    model_file = Str
Exemplo n.º 18
0
 def traits_view(self):
     v = View(
         UItem('scene',
               style='custom',
               height=250,
               width=600,
               resizable=True,
               editor=SceneEditor(scene_class=MayaviScene)))
     return v
Exemplo n.º 19
0
class PySPHViewer(HasTraits):

    scene = Instance(MlabSceneModel, ())

    scalar = Str("rho")

    scalar_list = List(Str)

    particle_array = Instance(ParticleArray)

    plot = Instance(PipelineBase)

    file_name = Str

    view = View(
        Group(Item(
            'scene',
            editor=SceneEditor(scene_class=MayaviScene),
            height=400,
            width=400,
            show_label=False
        )),
        Item('file_name'),
        Item('scalar', editor=EnumEditor(name='scalar_list')),
        resizable=True,
        title='PySPH viewer'
    )

    def update_plot(self):
        mlab = self.scene.mlab
        pa = self.particle_array
        if self.plot is None:
            self.plot = mlab.points3d(
                pa.x, pa.y, pa.z,
                getattr(pa, self.scalar),
                mode='point'
            )
            self.plot.actor.property.point_size = 3
        else:
            self.plot.mlab_source.reset(
                x=pa.x, y=pa.y, z=pa.z,
                scalars=getattr(pa, self.scalar)
            )

    def _particle_array_changed(self, pa):
        self.scalar_list = list(pa.properties.keys())
        self.update_plot()

    def _file_name_changed(self, fname):
        if os.path.exists(fname):
            data = load(fname)
            self.particle_array = data['arrays']['fluid']

    def _scalar_changed(self, scalar):
        pa = self.particle_array
        if pa is not None and scalar in pa.properties:
            self.update_plot()
Exemplo n.º 20
0
class Visualization(HasTraits):
  scene = Instance(MlabSceneModel, ())
  @on_trait_change('scene.activated')
  def update_plot(self, v, f):
    mlab.clf()
    if not isinstance(v, str):
      mlab.triangular_mesh(v[:, 0], v[:, 1], v[:, 2], f)
  # the layout of the dialog screated
  view = View(Item('scene', editor=SceneEditor(scene_class=MayaviScene),
    height=200, width=250, show_label=False), resizable=True)
class MyDialog(HasTraits):

    scene1 = Instance(MlabSceneModel, ())
    scene2 = Instance(MlabSceneModel, ())

    button1 = Button('Redraw')
    button2 = Button('Redraw')

    @on_trait_change('button1')
    def redraw_scene1(self):
        self.redraw_scene(self.scene1)

    @on_trait_change('button2')
    def redraw_scene2(self):
        self.redraw_scene(self.scene2)

    def redraw_scene(self, scene):
        # Notice how each mlab call points explicitely to the figure it
        # applies to.
        mlab.clf(figure=scene.mayavi_scene)
        x, y, z, s = np.random.random((4, 100))
        mlab.points3d(x, y, z, s, figure=scene.mayavi_scene)

    # The layout of the dialog created
    view = View(
        HSplit(
            Group(
                Item('scene1', editor=SceneEditor(), height=250, width=300),
                'button1',
                show_labels=False,
            ),
            Group(
                Item('scene2',
                     editor=SceneEditor(),
                     height=250,
                     width=300,
                     show_label=False),
                'button2',
                show_labels=False,
            ),
        ),
        resizable=True,
    )
Exemplo n.º 22
0
class Visualization(HasTraits):
    scene = Instance(MlabSceneModel, ())
    view = View(
        Item('scene',
             editor=SceneEditor(scene_class=MayaviScene),
             height=250,
             width=300,
             show_label=False),
        resizable=True  # We need this to resize with the parent widget
    )
Exemplo n.º 23
0
class MrcVisualization(HasTraits):
    level = Range(0, 100, 20) #mode='spinner')

    scene = Instance(MlabSceneModel, ())

    density_plot = Instance(PipelineBase)

    # the layout of the dialog screated
    view = View(Item('scene', editor=SceneEditor(scene_class=MayaviScene),
                     height=250, width=300, show_label=False),
                Group('level'),
                resizable=True # We need this to resize with the parent widget
                )

    alignedM = None
    color=(0.75, 0.75, 0.75)
    opacity=1

    @on_trait_change('level,scene.activated')
    def update_plot(self):
        # This function is called when the view is opened. We don't
        # populate the scene when the view is not yet open, as some
        # VTK features require a GLContext.

        # We can do normal mlab calls on the embedded scene.
        # self.scene.mlab.test_points3d()
        if self.alignedM is None:
            pass
        else:
            if self.density_plot is None:
                self.density_plot = self.plot_density(self.alignedM)
            else:
                # FIXME: update plot with specific level of contour
                pass

    def plot_density(self, s, level=0.2, ret_contour=False):
        self.scene.mlab.gcf().scene.background = (1,1,1)
        self.scene.mlab.gcf().scene.foreground = (0,0,0)
        
        src = self.scene.mlab.pipeline.scalar_field(s)
        
        mins = s.min()
        ptps = s.ptp()
        curr_contour = mins + level * ptps

        if ret_contour:
            return src, curr_contour
        else:
            density_plot = self.scene.mlab.pipeline.iso_surface(src, contours=[curr_contour,],
                opacity=self.opacity, color=self.color)
            return density_plot

    def setup(self, alignedM):
        self.alignedM = alignedM
Exemplo n.º 24
0
class Visualization(HasTraits):
    scene = Instance(MlabSceneModel, ())

    # the layout of the dialog screated
    view = View(
        Item('scene',
             height=600,
             width=600,
             show_label=True,
             editor=SceneEditor(scene_class=MayaviScene)),
        resizable=True  # We need this to resize with the parent widget
    )
Exemplo n.º 25
0
class Visualization(HasTraits):
    """mayavi application"""
    scene = Instance(MlabSceneModel, ())
    try:
        engine = mayavi.engine
    except:
        from mayavi.api import Engine
        engine = Engine()
        engine.start()

    def __init__(self, ycube):
        self.ycube = ycube
        self.initialize = True
        self.update_plot()

        self.plane1 = self.engine.scenes[0].children[0].children[0].children[0]
        self.plane2 = self.engine.scenes[0].children[0].children[0].children[1]
        self.iso_surface = self.engine.scenes[0].children[0].children[
            0].children[2]

    def show_iso(self, check_state):
        self.iso_surface.actor.actor.visibility = check_state

    def show_plane1(self, check_state):
        self.plane1.actor.actor.visibility = check_state
        self.plane1.implicit_plane.widget.enabled = check_state

    def show_plane2(self, check_state):
        self.plane2.actor.actor.visibility = check_state
        self.plane2.implicit_plane.widget.enabled = check_state

    @on_trait_change('scene.activated')
    def update_plot(self):
        data = self.ycube
        scalar_field_data = self.scene.mlab.pipeline.scalar_field(data)
        self.scene.mlab.pipeline.scalar_cut_plane(scalar_field_data,
                                                  plane_orientation='y_axes')

        self.scene.mlab.pipeline.scalar_cut_plane(scalar_field_data,
                                                  plane_orientation='z_axes')
        self.scene.mlab.pipeline.iso_surface(scalar_field_data)

        self.scene.mlab.outline()

    view = View(
        Item('scene',
             editor=SceneEditor(scene_class=MayaviScene),
             height=250,
             width=300,
             show_label=False),
        resizable=True  # We need this to resize with the parent widget
    )
Exemplo n.º 26
0
class PySPHViewer(HasTraits):

    scene = Instance(MlabSceneModel, ())

    plot = Instance(PipelineBase)

    view = View(Group(
        Item('scene',
             editor=SceneEditor(scene_class=MayaviScene),
             height=400,
             width=400,
             show_label=False)),
                resizable=True,
                title='PySPH viewer')
Exemplo n.º 27
0
class Visualization(HasTraits):
    scene = Instance(MlabSceneModel, ())
    view = View(Item('scene',
                     editor=SceneEditor(scene_class=MayaviScene),
                     height=0.9,
                     width=0.9,
                     show_label=False),
                resizable=True)

    def __init__(self, points, **traits):
        super(HasTraits, self).__init__(**traits)

        self.figure = self.scene.mlab.gcf()
        self.figure.scene.background = (1, 1, 1)
        self.figure.scene.foreground = (0, 0, 0)
Exemplo n.º 28
0
class Visualization(HasTraits):
    """
Be sure to .show() the QWidget before drawing anything,
because the VTK artists need the GLcontext to exist before
initialisation.
"""
    scene = Instance(MlabSceneModel, ())

    # the layout of the dialog screated
    view = View(Item('scene',
                     editor=SceneEditor(scene_class=MayaviScene),
                     height=250,
                     width=300,
                     show_label=False),
                resizable=True)
Exemplo n.º 29
0
    def create_scene_widget(self):
        """ Factory method to create the QWidget for the Mayavi scene.

        This follows the same approach as the Chaco example i.e. create a hidden
        traitsui view based on the mayavi SceneEditor and return it's 'control'
        to obtain the required QWidget.
        """
        from traitsui.api import View, Item
        from mayavi.core.ui.api import MayaviScene, SceneEditor
        view = View(Item('scene', show_label=False,
                         editor=SceneEditor(scene_class=MayaviScene)),
                         resizable=True)
        ui = self.edit_traits(view=view, parent=None, kind='subpanel')

        return ui.control
Exemplo n.º 30
0
class Visualization(HasTraits):
    scene = Instance(MlabSceneModel, ())

    @on_trait_change('scene.activated')
    def update_plot(self):
        self.scene.mlab.test_points3d()

    view = View(
        Item('scene',
             editor=SceneEditor(scene_class=MayaviScene),
             height=0,
             width=0,
             show_label=False),
        resizable=True  # We need this to resize with the parent widget
    )