andreasl | 4 Dec 2011 15:47
Picon

Newbie Qs regarding 3D networks

Hello,

As this is my first message here, first of all: many thanks for Mayavi. It is very impressive indeed.

I am only just starting out - got the general idea, worked through some examples. So these are proper newbie
questions. Beginning from

http://networkx.lanl.gov/examples/drawing/mayavi2_spring.html

[1] I would like to make the diameter of each graph edge (tube) depend on an associated weight value. My
impression is that tube_radius can only be a single value, not a vector, so I imagine a loop is required. Is
that correct?

[2] I am somewhat confused by the lines

   pts.mlab_source.dataset.lines = np.array(G.edges())
   tube = mlab.pipeline.tube(pts, tube_radius=0.01)

in that it is not immediately obvious that a points3d object has lines associated with it. Or are these
/created/ here (1st line)? Then how does the 2nd line 'know' that the tube shapes need to be applied to the
/lines/? Please point to relevant docs if this is explained somewhere.

[3] Would curved tubes be possible?

[4] What about arrowheads, for a directed graph?

I'm not sure how to even start approaching [3] and [4], so a general idea would be very welcome.

Thank you!

(Continue reading)

Bertrand | 5 Dec 2011 16:19
Picon
Favicon

Questions on the Volume module

Hello Mayavi Users,

This post is a duplicate of the one found here, but I haven't got any reply and the post is now buried...
I have 2 questions concerning the volume module. I was trying to visualize a 3D scalar field, starting from a StructuredPoints dataset. When the spacing along the axes is 1 (or larger), it works fine (like sgrid1 in the code below). But when the spacing gets smaller than 1, the volume is not displayed properly.
One thing which is fishy: the color of the volume gets more intense as the spacing increases. It seems like the volume module does not pick the right scalar information, but changing the "Scalar mode" from the application had no effect. The image_plane_widget works fine on the same grids.

My second question relates to the CTF. How can I set the vmin and vmax for transparency through a script? I tried to use the record script feature from the Mayavi GUI, but nothing happens on the record window when I change the "alpha" settings.

Code:
----------------------------------------------------
import numpy as np
from enthought.tvtk.api import tvtk
from enthought.tvtk.array_handler import get_vtk_array_type

#Structured points with spacing of 1
sgrid1 = tvtk.StructuredPoints(origin=np.array((0,0,0)),
                               spacing=np.array((1,1,1)),
                               dimensions=np.array((10,10,10)))

#Structured points with spacing of 0.1
sgrid2 = tvtk.StructuredPoints(origin=np.array((0,0,0)),
                               spacing=np.array((1e-1,1e-1,1e-1)),
                               dimensions=np.array((10,10,10)))

#Some scalar values
scalars = np.array([np.ones((10,10))*i for i in range(10)]).transpose(2,1,0)

sgrid1.point_data.scalars = (scalars.ravel())
sgrid1.point_data.scalars.name = 'scalars'
sgrid2.point_data.scalars = (scalars.ravel())
sgrid2.point_data.scalars.name = 'scalars'

from enthought.mayavi.sources.vtk_data_source import VTKDataSource
from enthought.mayavi.modules.outline import Outline
from enthought.mayavi.modules.axes import Axes
from enthought.mayavi.modules.image_plane_widget import ImagePlaneWidget
from enthought.mayavi.modules.volume import Volume
from enthought.mayavi import mlab
from enthought.mayavi.api import Engine
e1 = Engine()
e1.start()
s1 = e1.new_scene()
src1 = VTKDataSource(data = sgrid1)
e1.add_source(src1)
e1.add_module(Volume())
e1.add_module(ImagePlaneWidget())
e1.add_module(Outline())
e1.add_module(Axes())

e2 = Engine()
e2.start()
s2 = e2.new_scene()
src2 = VTKDataSource(data = sgrid2)
e2.add_source(src2)
e2.add_module(Volume())
e2.add_module(ImagePlaneWidget())
e2.add_module(Outline())
e1.add_module(Axes())

mlab.show()
----------------------------------------------------

My setup: Ubuntu 11.04 64bits with Mayavi2 v.3.4.0-1

Thanks a lot for your comments and help!
Bertrand

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
MayaVi-users mailing list
MayaVi-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mayavi-users
Gael Varoquaux | 6 Dec 2011 07:50
Favicon
Gravatar

Re: Questions on the Volume module

On Mon, Dec 05, 2011 at 04:19:01PM +0100, Bertrand wrote:
>    I have 2 questions concerning the volume module. I was trying to visualize
>    a 3D scalar field, starting from a StructuredPoints dataset. When the
>    spacing along the axes is 1 (or larger), it works fine (like sgrid1 in the
>    code below). But when the spacing gets smaller than 1, the volume is not
>    displayed properly.
>    One thing which is fishy: the color of the volume gets more intense as the
>    spacing increases. It seems like the volume module does not pick the right
>    scalar information, but changing the "Scalar mode" from the application
>    had no effect. The image_plane_widget works fine on the same grids.

I don't know the answer to this question. I believe that it is related to
the algorithm used by VTK to compute the Volume rendering. Maybe you can
ask on the VTK mailing lists.

>    My second question relates to the CTF. How can I set the vmin and vmax for
>    transparency through a script?

If you use mayavi.mlab.pipeline.volume:
see
http://github.enthought.com/mayavi/mayavi/mlab_pipeline_reference.html

I believe that the vmin and vmax arguments should do what you are looking
for.

Also, if you look at the docstring of this function:
https://github.com/enthought/mayavi/blob/master/mayavi/tools/modules.py#L519
if gives pointer on how to modify the CTF.

As a general rule, it is often useful to have a look at how to do things
with mlab, even if you want to use full object oriented programming at
the end of the day. Mlab is good for prototyping and trying things out.

HTH,

Gael

------------------------------------------------------------------------------
Cloud Services Checklist: Pricing and Packaging Optimization
This white paper is intended to serve as a reference, checklist and point of 
discussion for anyone considering optimizing the pricing and packaging model 
of a cloud services business. Read Now!
http://www.accelacomm.com/jaw/sfnl/114/51491232/
Gael Varoquaux | 6 Dec 2011 08:08
Favicon
Gravatar

Re: Newbie Qs regarding 3D networks

On Sun, Dec 04, 2011 at 03:47:33PM +0100, andreasl <at> club.lemonde.fr wrote:
> [1] I would like to make the diameter of each graph edge (tube) depend on an associated weight value. My
impression is that tube_radius can only be a single value, not a vector, so I imagine a loop is required. Is
that correct?

We can do slightly better, but it is non trivial. I posted some code to
do this recently on the enthought-dev mailing list (where many of the
Mayavi related discussions happen):
https://mail.enthought.com/pipermail/enthought-dev/2011-November/030194.html

You will need to study it and do some reading of the Mayavi documentation
on the pipeline and the difference modules to understand it.

> [2] I am somewhat confused by the lines

>    pts.mlab_source.dataset.lines = np.array(G.edges())
>    tube = mlab.pipeline.tube(pts, tube_radius=0.01)

> in that it is not immediately obvious that a points3d object has lines
> associated with it. Or are these /created/ here (1st line)?

Yes.

> Then how does the 2nd line 'know' that the tube shapes need to be
> applied to the /lines/?

Because they cannot be applied to anything else: tubes cannot be applied
to points, surfaces or volumes.

> Please point to relevant docs if this is explained somewhere.

The following documentation could be useful:
http://github.enthought.com/mayavi/mayavi/data.html

> [3] Would curved tubes be possible?

No, but you can approximate them with a specific graph introducing
intermediate nodes to create a curvature in between the nodes that you
are actually interested in.

> [4] What about arrowheads, for a directed graph?

Not easy at all. I suggest that you get more familiar with Mayavi (i.e.
really familiar) before trying to tackle this problem. It would probably
take me a few hours to get something going here.

> I'm not sure how to even start approaching [3] and [4], so a general
> idea would be very welcome.

If you don't have performance concerns, the easiest approach is to use a
for loop with other primitives, such as mlab.plot and mlab.quiver. Of
course, this will be much slower.

HTH,

Gael

------------------------------------------------------------------------------
Cloud Services Checklist: Pricing and Packaging Optimization
This white paper is intended to serve as a reference, checklist and point of 
discussion for anyone considering optimizing the pricing and packaging model 
of a cloud services business. Read Now!
http://www.accelacomm.com/jaw/sfnl/114/51491232/
Juha Jäykkä | 9 Dec 2011 16:50
Picon
Favicon

length of a curve

Hi list!

What is the best way of finding the length of a curve in mayavi? I have a 
small snippet, which works fine for a most curves, but not always.

In the snippet below "pd" is <tvtk_classes.poly_data.PolyData object at 
0xee00d4c>:

pd = foo.outputs[0]
PTS=pd.points.to_array()
lines=pd.lines
linesdata=lines.data.to_array()
l1=linesdata.reshape(PTS.shape)
curvelen=(((PTS[l1[:,1:]][:,1,:]-
            PTS[l1[:,1:]]:,0,:])**2).sum(axis=1)**.5).sum()

A related issue is with mlab.pipeline.stripper: if I use that while producing 
"foo", filtering the line (foo) with mlab.pipeline.tube later on will cause 
error messages (mayavi claims the vtk object contains no data) when I change 
the scalars! The same happens also with mlab.pipeline.surface if I have used 
DepthSortPolyData to construct what ever I feed to surface. Any idea why?

I would have thought setting scene.disable_render = True would prevent that, 
but it does not seem to have any effect (i.e. I see on screen as mayavi runs 
thourgh the script: first a surface appears, then a tube, then my title, then 
the title moves to the right location and finally the view angle is changed). 
Is this normal? Why?

Cheers,
Juha

------------------------------------------------------------------------------
Cloud Services Checklist: Pricing and Packaging Optimization
This white paper is intended to serve as a reference, checklist and point of 
discussion for anyone considering optimizing the pricing and packaging model 
of a cloud services business. Read Now!
http://www.accelacomm.com/jaw/sfnl/114/51491232/
Andreas | 20 Dec 2011 22:17
Picon

Re: Newbie Qs regarding 3D networks

Hello Gaël,

First, thanks for your answer and sorry for the delay with mine. I'm new to Python in general, and had a lot to figure out.

I used the code you linked to, with some modifications, particularly because I'm dealing with directed graphs (asymmetric adjacency matrix).

To get arrows, I made the tubes transparent and put a quiver3d on top (i.e. 'in') them:

p, li { white-space: pre-wrap; }

def plotarrows(offset):

posx = x[start_idx]

posy = y[start_idx]

posz = z[start_idx]

dirx = x[stop_idx] - posx

diry = y[stop_idx] - posy

dirz = z[stop_idx] - posz

# push the start of the arrows away from the node sphere centres

# (offset = 0.5 means they _start_ mid-way the tube)

posx = posx + offset*dirx

posy = posy + offset*diry

posz = posz + offset*dirz

arrows = mlab.quiver3d(posx, posy, posz, dirx, diry, dirz,

# sqrt() boosts smaller weights visually

scalars = np.sqrt(edge_scalar),

scale_mode = 'scalar',

scale_factor = 0.0075,

mode = 'arrow',

resolution = 6,

color = (1, 0, 0))

return arrows


That results in something like [1].

I tried to go fancy and animate the arrows, by creating three quiver3ds, at different offsets, and switching them on/off (like a traffic light):

p, li { white-space: pre-wrap; }

<at> mlab.animate(delay=10)

def anim():

ar = []

ar.append(plotarrows(0.1)); ar[0].stop()

ar.append(plotarrows(0.4)); ar[1].stop()

ar.append(plotarrows(0.7)); ar[2].stop()

while 1:

for i in [0, 1, 2]:

ar[i-1].stop()

ar[i].start()

yield


This works, but too slowly for practical use with large graphs (even when the delay is set at 10ms - the true delay is much larger on my system). I tried some alternatives: (1) using _hideshow() instead of stop() and start(); (2) creating only one quiver3d, and updating its x, y and z parameters while cycling through the three offsets, using mlab_source as explained in [2]. I didn't get a noticeable speed increase. Any alternatives for this? I haven't quite figured out the details of the pipeline system yet...

Best regards,

Andreas

[1] http://imageshack.us/photo/my-images/683/testsnapshot.png/
[2] http://github.enthought.com/mayavi/mayavi/mlab_animating.html?highlight=animating%20data

On 06/12/11 07:08, Gael Varoquaux wrote:
On Sun, Dec 04, 2011 at 03:47:33PM +0100, andreasl <at> club.lemonde.fr wrote:
[1] I would like to make the diameter of each graph edge (tube) depend on an associated weight value. My impression is that tube_radius can only be a single value, not a vector, so I imagine a loop is required. Is that correct?
We can do slightly better, but it is non trivial. I posted some code to do this recently on the enthought-dev mailing list (where many of the Mayavi related discussions happen): https://mail.enthought.com/pipermail/enthought-dev/2011-November/030194.html You will need to study it and do some reading of the Mayavi documentation on the pipeline and the difference modules to understand it.
------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
_______________________________________________
MayaVi-users mailing list
MayaVi-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mayavi-users
Michele Mattioni | 28 Dec 2011 11:24
Picon
Gravatar

What is the best way to tackle this two bugs

Dear Mayavi users,

I was wondering if you can replicate this two bugs or not with current master:

https://github.com/enthought/mayavi/issues/21
https://github.com/enthought/mayavi/issues/20

both bugs are 'regression' bugs. Everything was working before with
Mayavi 3.6.0.
The main trouble is that a program I wrote is using the Qt embedding
and the picker for the mouse, and these two bugs are stopping the
release of the new upcoming version.

https://github.com/mattions/neuronvisio/issues/34
https://github.com/mattions/neuronvisio/issues/32

I'm not familiar with Mayavi source code, however I could try to help
if you point me in the right direction!
Thanks!

Cheers,
Michele.

------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev

Gmane