2017-06-28 7 views
0

mlab iso_surfaceモジュールを使用する単純なMayaviスクリプトアプリケーションを構築しようとしています。Mayaviアプリケーションでmlab iso_surfaceモジュールを使用する方法

しかし、私は私のmayavi iso_surfaceプロットを表示し、空の "プロパティを編集"ウィンドウを表示する2つのウィンドウをスローアップ私のアプリを実行する。 Mayaviシーンが「プロパティの編集」ウィンドウの指定されたビューレイアウトに表示されていないようです。

私の質問は:mayavi iso_surfaceのシーンがビューレイアウトに表示されないのはなぜですか?

この動作を表示する簡単なテストスクリプトを下に貼り付けます。私はCanopバージョン2.1.1.3504(64ビット)、Windows 10システムではPython 3.5.2を使用しています。

[注:私は元の質問を変更して別の質問を追加しました。 Rangeオブジェクト(mult_s)からの入力で 's'データを更新するにはどうすればよいですか?私はこれを下に行ったが成功しなかった。これは、アップスロー:TraitError: Cannot set the undefined 's' attribute of a 'ArraySource' object.]

class Isoplot1(HasTraits): 
    scene = Instance(MlabSceneModel,()) 
    mult_s = Range(1, 5, 1) 

    @on_trait_change('scene.activated') 
    def _setup(self): 
     # Create x, y, z, s data 
     L = 10. 
     x, y, z = np.mgrid[-L:L:101j, -L:L:101j, -L:L:101j] 
     self.s0 = np.sqrt(4 * x ** 2 + 2 * y ** 2 + z ** 2)   

     # create the data pipeline 
     self.src1 = mlab.pipeline.scalar_field(x, y, z, self.s0) 

     # Create the plot 
     self.plot1 = self.scene.mlab.pipeline.iso_surface(
      self.src1, contours=[5, ], opacity=0.5, color=(1, 1, 0) 
     ) 

    @on_trait_change('mult_s') 
    def change_s(self): 
     self.src1.set(s=self.s0 * self.mult_s) 

    # Set the layout 
    view = View(Item('scene', 
        editor=SceneEditor(scene_class=MayaviScene), 
        height=400, width=600, show_label=False), 
       HGroup('mult_s',), 
       resizable=True 
       ) 

isoplot1 = Isoplot1() 
isoplot1.configure_traits() 

答えて

2

があなたの代わりに、これは起こるべきではありませんmlab.pipeline.scalar_fieldself.scene.mlab.pipeline.scalar_field使用している場合。

一般に、イニシャライザでのビジュアライゼーションの作成は避けてください。代わりに、scene.activatedイベントが発生したときに常にシーンを設定する必要があります。生のmlabで安全に使用するには、次のようにコードを書き直す必要があります。

from mayavi import mlab 
from traits.api import HasTraits, Instance, on_trait_change 
from traitsui.api import View, Item 
from mayavi.core.ui.api import MayaviScene, SceneEditor, MlabSceneModel 
import numpy as np 

class Isoplot1(HasTraits): 
    scene = Instance(MlabSceneModel,()) 

    @on_trait_change('scene.activated') 
    def _setup(self): 
     # Create x, y, z, s data 
     L = 10. 
     x, y, z = np.mgrid[-L:L:101j, -L:L:101j, -L:L:101j] 
     s = np.sqrt(4 * x ** 2 + 2 * y ** 2 + z ** 2) 

     # create the data pipeline 
     self.src1 = mlab.pipeline.scalar_field(x, y, z, s) 

     # Create the plot 
     self.plot1 = self.scene.mlab.pipeline.iso_surface(
      self.src1, contours=[5, ], opacity=0.5, color=(1, 1, 0) 
     ) 

    # Set the layout 
    view = View(Item('scene', 
        editor=SceneEditor(scene_class=MayaviScene), 
        height=400, width=600, show_label=False), 
       resizable=True 
       ) 

isoplot1 = Isoplot1() 
isoplot1.configure_traits() 

あなたはおそらくすでにこれを知っているが、念のために、あなたはまた、ドキュメント内の他のmayavi interactive examplesのいくつかを見てみることができます。

+0

速い応答のPrabhu、あなたの変更されたコードは私のために働く。 私は実際にコードの試行をhttp://docs.enthought.com/mayavi/mayavi/building_applications.htmlで提供されている例に基づいていましたが、ここでは上記で提案したアプローチを使用するための警告が表示されています。 – dreme

関連する問題