enthought / mayavi

3D visualization of scientific data in Python
http://docs.enthought.com/mayavi/mayavi/
Other
1.3k stars 284 forks source link

Scene widgets do not refresh fully after data source update in pipeline #1155

Open KestutisMa opened 2 years ago

KestutisMa commented 2 years ago

Hi, Just starting to use Mayavi, and noticed few minor issues: image_plane_widget and vector_cut_plane are not fully updated after data source update, when new array dimensions differs from old, via self.our_scalar_field_src = newdata and self.our_vector_field_src = new_vec

Screenshot shows, that while vectors updated to new dimensions, ImplicitPlane widget of vector_cut_plane, does not. Also, image_plane_widget dimensions not updated. image

src = self.our_scalar_field_src = self.scene.mlab.pipeline.scalar_field(s)
src = self.scene.mlab.pipeline.image_plane_widget(src, plane_orientation='z_axes', slice_index=1,  )
viz = self.scene.mlab.pipeline.outline(src)  
src_vec = self.our_vector_field_src = self.scene.mlab.pipeline.vector_field(vector_data[:,:,:,0],vector_data[:,:,:,1],vector_data[:,:,:,2]) 
viz = self.scene.mlab.pipeline.vector_cut_plane(src_vec)
viz.implicit_plane.widget.normal_to_z_axis = True

However I noticed such workarounds:

To update image_plane_widget:

            ##update scalars workaround
            self.our_scalar_field_src.scalar_data = scalar_data
            image_plane_widget = self.scene.mayavi_scene.children[0].children[0].children[0] 
            image_plane_widget.ipw.plane_orientation = 'y_axes'
            image_plane_widget.ipw.plane_orientation = 'z_axes'

To update vector_cut_plane:

            self.our_vector_field_src.vector_data = vector_data
            #1. delete old
            # self.scene.mayavi_scene.scene.actor_list[6:7] = []
            module_manager1 = self.scene.mayavi_scene.children[1].children[0]
            module_manager1.children[0:1] = []

            ##2. create new VectorCurPlane
            from mayavi.modules.vector_cut_plane import VectorCutPlane
            vector_cut_plane = VectorCutPlane()
            array_source1 = self.scene.mayavi_scene.children[1]
            self.scene.engine.add_filter(vector_cut_plane, array_source1)
            vector_cut_plane = self.scene.mayavi_scene.children[1].children[0].children[0]
            vector_cut_plane.implicit_plane.widget.normal_to_z_axis = True

This gives correct result, but makes code less readable: image

Question: how to update plot data source correctly? Is it best way to remove object from pipeline module_manager1.children[0:1] = []?