Closed kitchoi closed 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))```
I am not sold on this feature.
add_dataset
gets a simphony dataset an kwargs but returns a source which is already added to a scene. It looks to me that the behaviour of this function is a little confused. add_dataset
is part of the visualization api of simphony (similar to show and snapshot) something that all visualization plugins need to implementFor 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?
one sould be able to just also do.
source = EngineSource(engine=some_engine, dataset = "particles", point_vector='MASS)
Indeed add_dataset
is intended as a shortcut function mimicking the behaviour of mlab.pipeline.add_dataset
, done for convenience
I prefer the explicit code using EngineSource than the proposed add_dataset
.
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...
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
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!)
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.
Will open another issue about the refactoring as that's a separate problem
@itziakos, question: is the signature point_scalars=None, point_vectors=None...
for show
and snapshot
desired?
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
vspoint_scalars_name
I would say yes.- If you are refering to the signature of
show
andsnapshot
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
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.
So that a user can do something like this:
Similar to
show
, butshow
is synchronousThis function can be used by
show
andsnapshot
. The signature for these functions should be the same.