Stuart Mumford | 6 Aug 12:27 2012
Picon

Colouring a Surface from a set of Points

Hello,

I have an annoying problem that I can't seem to solve at all.

I am using a set of points (generated from ~50 streamlines) to generate a surface that supposedly follows my magnetic fieldlines. I am using the SurfaceReconstructionFilter to generate a ImageData set from which the isosurface is generated. Then once I have the isosurface I extract the PolyData for the surface and use the normals to generate a velocity perpendicular to the surface.

The problem comes when I want to then colour the isosurface with the values I have just calculated. I have tried to go back and find an attribute in the ImageData set to set some scalar point data and use that to colour the surface but nothing I try seems to work.

Here is the code snippet I am using:

#My magnetic field

bfield = mlab.pipeline.vector_field(f.w_sac['b3'][cube_slice] * 1e3,

f.w_sac['b2'][cube_slice] * 1e3,

f.w_sac['b1'][cube_slice] * 1e3,

name="Magnetic Field")


#This uses a custom subclass of Streamline so I can manually set the seed points.

field_lines = sStreamline(seed_points = np.array(seeds))

bfield.add_child(field_lines)


#Get the points from the streamlines

f_lines = field_lines.outputs[0].points

f_points = tvtk.PolyData(points=f_lines)


#Create the surface

sr = tvtk.SurfaceReconstructionFilter(input=f_points,sample_spacing=spacing)

sr.update()


#Add the surface to Mayavi

tube = mlab.pipeline.surface(sr.output)

tube.enable_contours=True

tube.contour.auto_contours = False

tube.contour.contours = [0.0]


#Get and compute the normals

tube_PD = tube.contour.outputs[0]

norms = tvtk.PolyDataNormals()

norms.input = tube_PD

norms.compute_point_normals = True

norms.flip_normals = True

norms.update()

normals = np.array(norms.output.point_data.normals)


#Calculate the projection of V on the normal vector.

vperp = []

for i, perp in enumerate(normals):

vperp.append(np.dot(perp, np.array([v3i[i],v2i[i],v1i[i]])))

vperp = np.array(vperp)


#Now I wish to colour tube with the vperp array.


Any suggestions would be greatly appreciated!

Thanks
Stuart
p, li { white-space: pre-wrap; } p, li { white-space: pre-wrap; } p, li { white-space: pre-wrap; } p, li { white-space: pre-wrap; }
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
MayaVi-users mailing list
MayaVi-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mayavi-users
Gael Varoquaux | 6 Aug 15:27 2012

Re: Colouring a Surface from a set of Points

Hi,

I don't think that you can, without some C-level programming, cleanly
insert data in an existing object in the middle of the VTK pipeline.

What you could do, is to grab the info that you are interested in from
the object that has been created by your current pipeline, and create a
new one, adding the additional data that you want to display.

1. Have look at
http://docs.enthought.com/mayavi/mayavi/data.html#the-flow-of-data
to understand better where you want to fish the info from your existing
pipeline,

2. also,
http://docs.enthought.com/mayavi/mayavi/data.html#inspecting-the-internals-of-the-data-structures
to figure out how to retrieve the info

3. and finally
http://docs.enthought.com/mayavi/mayavi/data.html#polydata
to understand how to create an object with the info output by the
pipeline and your additional data.

HTH,

Gael

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
Stuart Mumford | 7 Aug 12:45 2012
Picon

Re: Colouring a Surface from a set of Points

Hi,

Thank you that worked a treat! I didn't realise that mlab.pipeline.surface would happily take PolyData.

Stuart

On 6 August 2012 14:27, Gael Varoquaux <gael.varoquaux <at> normalesup.org> wrote:
Hi,

I don't think that you can, without some C-level programming, cleanly
insert data in an existing object in the middle of the VTK pipeline.

What you could do, is to grab the info that you are interested in from
the object that has been created by your current pipeline, and create a
new one, adding the additional data that you want to display.

1. Have look at
http://docs.enthought.com/mayavi/mayavi/data.html#the-flow-of-data
to understand better where you want to fish the info from your existing
pipeline,

2. also,
http://docs.enthought.com/mayavi/mayavi/data.html#inspecting-the-internals-of-the-data-structures
to figure out how to retrieve the info

3. and finally
http://docs.enthought.com/mayavi/mayavi/data.html#polydata
to understand how to create an object with the info output by the
pipeline and your additional data.

HTH,

Gael


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
MayaVi-users mailing list
MayaVi-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mayavi-users
Gael Varoquaux | 7 Aug 14:08 2012

Re: Colouring a Surface from a set of Points

On Tue, Aug 07, 2012 at 11:45:12AM +0100, Stuart Mumford wrote:
>    Thank you that worked a treat! I didn't realise that mlab.pipeline.surface
>    would happily take PolyData.

Makes me a happy man. I was afraid that my suggestion would be a bit
intricated, but you seem to find your way around the objects.

G

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
Stuart Mumford | 7 Aug 14:59 2012
Picon

Re: Colouring a Surface from a set of Points

I have one more question.

I am now creating my own tvtk contourfilter and feeding the output from that into mlab.pipeline.surface. When I update the data for the pipeline that leads into the contour filter (seed array > Stream_Tracer > SurfaceReconstructionFilter > ContourFilter) everything upto the mayavi surface updates, but the surface wont re-draw with the updated data in the contour filter.

How can I make the surface re-draw the new contour filter pipeline?

Thanks again
Stuart

On 7 August 2012 13:08, Gael Varoquaux <gael.varoquaux <at> normalesup.org> wrote:
On Tue, Aug 07, 2012 at 11:45:12AM +0100, Stuart Mumford wrote:
>    Thank you that worked a treat! I didn't realise that mlab.pipeline.surface
>    would happily take PolyData.

Makes me a happy man. I was afraid that my suggestion would be a bit
intricated, but you seem to find your way around the objects.

G

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
MayaVi-users mailing list
MayaVi-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mayavi-users
Gael Varoquaux | 7 Aug 15:08 2012

Re: Colouring a Surface from a set of Points

On Tue, Aug 07, 2012 at 01:59:43PM +0100, Stuart Mumford wrote:
>    I am now creating my own tvtk contourfilter and feeding the output from
>    that into mlab.pipeline.surface. When I update the data for the pipeline
>    that leads into the contour filter (seed array > Stream_Tracer >
>    SurfaceReconstructionFilter > ContourFilter) everything upto the mayavi
>    surface updates, but the surface wont re-draw with the updated data in the
>    contour filter.

Indeed, the pipeline has been broken, so the refresh model no longer
works.

>    How can I make the surface re-draw the new contour filter pipeline?

How important is this? If it really is, you can always build your own
subclass of Filter (mayavi.core.filter.Filter), that does everything
right, in particular implements the 'update_pipeline' method.
Maybe you can actually subclass mayavi.filters.contour.Contour. Anyhow,
this will require some work.

Maybe you can simple get away with registering a filter on 'data_changed'
(or 'pipeline_changed', I am not sure), using the Trait's event
mechanism:

http://code.enthought.com/projects/traits/docs/html/traits_user_manual/notification.html#dynamic-notification

HTH,

Gael

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
Herbert Pablo | 8 Aug 20:41 2012

strange shading

Hey all,


I have been doing some relatively simple plotting using ubuntu 11.10 and I am getting strange results. For instance if i plot a sphere...half the sphere is in shadow and the other half is fine.


A simple command like:

a=mv.mesh(x, y, z, color=(1,0,0))

where x, y, and z represent coordinates for the surface of a sphere, comes out like the attached picture.  I thought there might be a problem with the colormap, but I can run this exact same code on the same version of ubuntu on my laptop and there is no shadowing. It's all the same shade of red. Any thoughts?

Thanks,
Bert Pablo


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
MayaVi-users mailing list
MayaVi-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mayavi-users
Gael Varoquaux | 8 Aug 21:17 2012

Re: strange shading

Hi Herbert,

On Wed, Aug 08, 2012 at 01:41:41PM -0500, Herbert Pablo wrote:
> where x, y, and z represent coordinates for the surface of a sphere, comes
> out like the attached picture.  I thought there might be a problem with the
> colormap, but I can run this exact same code on the same version of ubuntu
> on my laptop and there is no shadowing. It's all the same shade of red.

Are you telling us that depending on the computer that you run this on,
you get different shading results? This seems to me like a bug in the
OpenGL drivers on the computer that doesn't work fine.

The bad news is that this does happen sometimes, and I know no solution
:(.

Gael

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
Tom Bjerck | 9 Aug 04:02 2012
Picon

Surf, warp_scale and axes labels.

I want to plot the function A(x,y) = 28x + 28y - 2x^2 - 2y^2 - 2xy. To do this I
made the following python script:

import mayavi.mlab as mlab
import numpy as np

def A(x,y):
    return 28*x + 28*y - 2*x**2 - 2*y**2 - 2*x*y

x, y = np.mgrid[0:14:100j,0:14:100j]

mlab.surf(x,y,A)
mlab.axes(nb_labels=6)
mlab.outline()
mlab.show()

Since the x and y axis ranges from 0 to 14, and the z-axis from -392 to 131 it is
hard to see the plot, and to remedy this I added the warp_scale='auto' keyword
argument to the surf() call:

mlab.surf(x,y,A,warp_scale='auto')

But now the labeling along the x,y and z-axis is wrong; i.e. the labels seem to
also have been scaled. With warp_scale='auto' the labels in x and y direction
range from 0 to 99 instead of the correct 0 to 14.

Is there a way to have the labels show the original x, y and z values?

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
Gael Varoquaux | 9 Aug 06:45 2012

Re: Surf, warp_scale and axes labels.

On Thu, Aug 09, 2012 at 02:02:28AM +0000, Tom Bjerck wrote:
> Is there a way to have the labels show the original x, y and z values?

Not that I know of, sorry.

Gael

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

Gmane