simphony / simphony-mayavi

The mayavi adapters to the simphony framework
BSD 2-Clause "Simplified" License
0 stars 1 forks source link

Expose add-to-scene function to mayavi_tools #134

Closed kitchoi closed 8 years ago

kitchoi commented 8 years ago

So that a user can do something like this:

from simphony.visualization import mayavi_tools
from mayavi import mlab

engine = ... # do some stuff setting up a simulation...

# add a bunch of datasets to the same scene
source1 = mayavi_tools.add_to_scene(engine.get_dataset("lattice1"), point_scalar="TEMPERATURE")  # show temperature only
source2 = mayavi_tools.add_to_scene(engine.get_dataset("lattice2"), point_vector="MASS")

# run the simulation N times
# update the scene
for i in xrange(N):
    engine.run()
    source1.update()
    source2.update()
    mlab.savefig("saved_{}.png".format(i))

Similar to show, but show is synchronous

This function can be used by show and snapshot. The signature for these functions should be the same.

kitchoi commented 8 years ago

With #136, the example would look like this instead:

from simphony.visualization import mayavi_tools
from mayavi import mlab

engine = ... # do some stuff setting up a simulation...

# add a bunch of datasets to the same scene
source1 = mayavi_tools.add_dataset(engine.get_dataset("lattice1"), point_scalar="TEMPERATURE")
mayavi_tools.add_default_modules(source1)

source2 = mayavi_tools.add_dataset(engine.get_dataset("lattice2"), point_vector="MASS")
mayavi_tools.add_default_modules(source2)

# run the simulation N times
# update the scene
for i in xrange(N):
    engine.run()
    source1.update()
    source2.update()
    mlab.savefig("saved_{}.png".format(i))```
itziakos commented 8 years ago

I am not sold on this feature.

For example:

   source = EngineSource(engine=some_engine)
   source.dataset = "particles"
   source.point_vector = 'MASS'
   from mayavi import mlab

   # add to the default pipeline
   mlab.pipline.glypy(source)
  ... add the mayavi modules you like.

Is the feature just adding a sortcut function?

itziakos commented 8 years ago

one sould be able to just also do.

source = EngineSource(engine=some_engine, dataset = "particles", point_vector='MASS)
kitchoi commented 8 years ago

Indeed add_dataset is intended as a shortcut function mimicking the behaviour of mlab.pipeline.add_dataset, done for convenience

itziakos commented 8 years ago

I prefer the explicit code using EngineSource than the proposed add_dataset.

kitchoi commented 8 years ago

One can do

source = EngineSource(engine=some_engine, dataset="particles")

but not

source = EngineSource(engine=some_engine, dataset="particles", point_scalars_name="MASS")

because the vtk cuds are not initialised at the time when point_scalars_name is set. Will have to overload __init__ in order to achieve this...

itziakos commented 8 years ago

because the vtk cuds are not initialised at the time when point_scalars_name is set.

That is a know issue with HasTraits classes and I would register it a a bug. So the current owrkaround would be that.

point_scalars_name="MASS" is set after initialization

You also point to the right solution by the need to control the order of initialization. This can be done with overriding __init__ or providing an alternative contructor (class method) that will do

@classmethod
def create_and_select(cls, engine, dataset, point_vector):
      source = cls(engine=engine)
      source.dataset = "particles"
      source.point_vector = 'MASS'
      return source

The contructor can also avoid the ugly ..._name postfix

kitchoi commented 8 years ago

I am more inclined towards the constructor class method.

Despite the less-than-ideal side-effect-and-return-value behaviour of add_dataset, it also has an added benefit of refactoring similar codes in show and snapshot and the GUI for mayavi2. (duplicated 3 times!)

kitchoi commented 8 years ago

mlab.pipeline.add_dataset accepts tvtk.dataset or mayavi source and return the source too. That leads me to think that the function would be desired by users.

kitchoi commented 8 years ago

Will open another issue about the refactoring as that's a separate problem

kitchoi commented 8 years ago

@itziakos, question: is the signature point_scalars=None, point_vectors=None... for show and snapshotdesired?

itziakos commented 8 years ago

mlab.pipeline.add_dataset accepts tvtk.dataset or mayavi source and return the source too. That leads me to think that the function would be desired by users.

[personal opinion] A simphony CUDS dataset is not the same as a TVTK.dataset and I would like to avoid confusing them.

@itziakos, question: is the signature point_scalars=None, point_vectors=None... for show and snapshot desired?

  • if you are refering to point_scalars vs point_scalars_name I would say yes.
  • If you are refering to the signature of show and snapshot having these special mayavi specific keywords, I would personally prefer to not have them and have a more generic signature described in the visualization plugin api of simphony and thus supported by all the visualization plugins. Ideally there should be a proposal for extending the singature of show and snapshot providing additional info on describing a basic visualization template which we then can translate to mayavi visualizations
kitchoi commented 8 years ago

162 is superseded by #164.

Changing the signature of show and snapshot became less crucial given that now the CUDSSource can be initialised with a user-friendly signature. We may revisit this matter (show and snapshot signatures) later. Closing via #164.