Stuart Mumford | 6 Aug 2012 12:27
Picon
Gravatar

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 2012 15:27
Favicon
Gravatar

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 2012 12:45
Picon
Gravatar

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 2012 14:08
Favicon
Gravatar

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 2012 14:59
Picon
Gravatar

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 2012 15:08
Favicon
Gravatar

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/

Gmane