# Isosurface and cuts

18 messages
Open this post in threaded view
|

## Isosurface and cuts

 Hi everybody, I am new to mayavi and I have some trouble getting my current task accomplished with it. Basically, my problems boil down to two problems: 1. I have a volume-data set f(x,y,z) but x,y,z are just the indeces of x*c_1+y*c_2+z*c_3, the c_i are non-orthogonal vectors. If I just plot the datafile, the outcome is some kind of distorted. Is there a canonical way in mayavi to solve such a problem? 2. After this plot is fabricated, I would like to define arbitrary layers that cut through the surface and display them in a nice way. Can anybody give me a hint on that problem? Thank you very much in advance, hope to hear from you, Chris _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev
Open this post in threaded view
|

## Re: Isosurface and cuts

 On Thu, Jan 12, 2012 at 11:38 AM, Christoph Piefke < [hidden email]> wrote: > Hi everybody, > > I am new to mayavi and I have some trouble getting my current task > accomplished with it. > Basically, my problems boil down to two problems: > > 1. > I have a volume-data set f(x,y,z) but x,y,z are just the indeces of > x*c_1+y*c_2+z*c_3, the c_i are non-orthogonal vectors. If I just plot the > datafile, the outcome is some kind of distorted. > > Is there a canonical way in mayavi to solve such a problem? > I'm no expert at this, but I would imagine mayavi is built to understand Cartesian coordinates.  Is it possible to do some sort of coordinate transformation into the Cartesian representation and then just plot that data? > > 2. After this plot is fabricated, I would like to define arbitrary layers > that cut through the surface and display them in a nice way. Can anybody > give me a hint on that problem? > The examples that come with ETS/EPD use the scalar cut plane to allow you to slice through a 3d object and project out the 2d plane interactively. This may be a step towards what you want to do. > > Thank you very much in advance, hope to hear from you, Chris > > > > _______________________________________________ > Enthought-Dev mailing list > [hidden email] > https://mail.enthought.com/mailman/listinfo/enthought-dev> _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev
Open this post in threaded view
|

## Re: Isosurface and cuts

 On Thu, Jan 12, 2012 at 11:53:30AM -0500, Adam Hughes wrote: > > 1. > > I have a volume-data set f(x,y,z) but x,y,z are just the indeces of > > x*c_1+y*c_2+z*c_3, the c_i are non-orthogonal vectors. If I just plot the > > datafile, the outcome is some kind of distorted. > > Is there a canonical way in mayavi to solve such a problem? Use a StructuredGrid data structure: http://github.enthought.com/mayavi/mayavi/data.html#structuredgridIt's quite tedious to generate and will slow down the visualization, but is very versatile. > > 2. After this plot is fabricated, I would like to define arbitrary layers > > that cut through the surface and display them in a nice way. Can anybody > > give me a hint on that problem? > The examples that come with ETS/EPD use the scalar cut plane to allow you > to slice through a 3d object and project out the 2d plane interactively. > This may be a step towards what you want to do. Indeed, you want to apply a scalar cut plane to this. If src is you StructuredGrid, you can do     mlab.pipeline.scalar_cut_plane(src) See http://github.enthought.com/mayavi/mayavi/mlab.html#assembling-pipelines-with-mlaband the remaining of the section. HTH, Gaël _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev
Open this post in threaded view
|

## Re: Isosurface and cuts

 Hello everybody, thank you very much for your hints, i managed to accomplish what I wanted to do, plot my volumetric data on a structured grid. I also managed to plot the iso-surfaces of interest from my data, but since I have more than one set of data, I had do something like mlab.pipeline.iso_surface(sgrid,contours=[0.0],opacity=0.4) mlab.pipeline.iso_surface(sgrid2,contours=[0.0],opacity=0.4) mlab.pipeline.iso_surface(sgrid3,contours=[0.0],opacity=0.4) to put them into one image. Is it possible to group them in a smarter way? I am asking, because I have to cut these iso-surfaces for some special values. At the moment mlab.pipeline.scalar_cut_plane(sgrid) mlab.pipeline.scalar_cut_plane(sgrid2) and so on give me two cut planes, one for each data set. But I need one plane for the whole dataset. I also remember something about sending extracted 2d information to matplotlib, but I cannot find the reference. Does anybody else remember how I can do that? Thanks a lot, Chris _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev
Open this post in threaded view
|

## Re: Isosurface and cuts

 On Mon, Jan 16, 2012 at 02:54:51PM +0100, Christoph Piefke wrote: > Is it possible to group them in a smarter way? No really. It is an ill-defined operation: if at a given point, one dataset has a value of .3 and the other one .5, what should be the value that you assign to that point? If you now the answer to that question, you can always sample the datasets on comon points and implement that answer. Ideally you would do that using scipy.interpolate or scipy.ndimage code that takes in account your knowledge of the dataset, as such a problem is really unrelated to visualization. Worst case, you can always use Mayavi's mechanism to do that: http://github.enthought.com/mayavi/mayavi/data.html#probing-data-at-given-positionsyou can probe on a regular grid, and then reinject it in mayavi using an mlab.pipeline.scalar_field. > I also remember something about sending extracted 2d information to > matplotlib, but I cannot find the reference. Does anybody else remember > how I can do that? You can get the 2D data out of a scalar cut plane using: out = scp.implicit_plane.outputs[0] out.point_data.scalars.to_array() Note that it is a flatten version of the data and that you will have to reshape it. HTH, Gael _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev
Open this post in threaded view
|

## Re: Isosurface and cuts

 > No really. It is an ill-defined operation: if at a given point, one > dataset has a value of .3 and the other one .5, what should be the value > that you assign to that point? > Okay, I get that. Perhaps I was unable to state my question properly, what I meant is something like sgrid = [ tvtk.StructuredGrid(dimensions=(kdiv[0], kdiv[1], kdiv[2])) for i in range(0,nBan) ] . This is just a result of my lack of python knowledge ;) > > You can get the 2D data out of a scalar cut plane using: > > out = scp.implicit_plane.outputs[0] > out.point_data.scalars.to_array() > > Note that it is a flatten version of the data and that you will have to > reshape it. > And here I am lost again. I extracted the data, but I do not understand what I get. out.point_data.scalars.to_array() is a 1d dataset with the size of my original volumetric data. I can reshape that in a 3d array, but on what grid do I plot it then? I very much appreciate your patience with this python and mayavi noob, regards, Chris _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev
Open this post in threaded view
|

## Re: Isosurface and cuts

 On Tue, Jan 17, 2012 at 02:23:34PM +0100, Christoph Piefke wrote: > > Not really. It is an ill-defined operation: if at a given point, one > > dataset has a value of .3 and the other one .5, what should be the value > > that you assign to that point? > Okay, I get that. Perhaps I was unable to state my question properly, what I meant is something like > sgrid = [ tvtk.StructuredGrid(dimensions=(kdiv[0], kdiv[1], kdiv[2])) for i in range(0,nBan) ] . I am sorry, I don't understand. Are you saying that your data are located on the same grid? In the expression above, i is not relevant in the loop. > > You can get the 2D data out of a scalar cut plane using: > > out = scp.implicit_plane.outputs[0] > > out.point_data.scalars.to_array() > > Note that it is a flatten version of the data and that you will have to > > reshape it. > And here I am lost again. I extracted the data, but I do not understand > what I get. out.point_data.scalars.to_array() is a 1d dataset with the > size of my original volumetric data. > I can reshape that in a 3d array, but on what grid do I plot it then? Granted, I was bullshitting. I wrote that last email too quickly. What you want is: out = scp.cutter.outputs[0] data = out.point_data.scalars.to_array() The points on which the data are located are: points = out.points.to_array() Sure, it's a mouthfull to work with, as they are not regularly spaced :). That kind of difficulties is what makes working with 3D data challenging. HTH, Gael _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev
Open this post in threaded view
|

## Re: Isosurface and cuts

 Hi again, | I am sorry, I don't understand. Are you saying that your data are located | on the same grid? In the expression above, i is not relevant in the loop. --->  Yes :) I just need #i copies of that. Again, my python-noobnes. > Granted, I was bullshitting. I wrote that last email too quickly. > What you want is: > > out = scp.cutter.outputs[0] > data = out.point_data.scalars.to_array() > > The points on which the data are located are: > > points = out.points.to_array() > > Sure, it's a mouthfull to work with, as they are not regularly spaced :). > That kind of difficulties is what makes working with 3D data challenging. > So this is great, thank you very much! I got access to alle the relevant data I am interested in and now I am processing it. This raised some more questions. At first I tried to rotate the normal of the cut plane parallel to the z-axes, so I can make a 2d plot out of the data. Good thing is, a rotation takes place, but some things I do not understand: In what coordinate system is the normal given? How can I directly set the coordinates of this thick point that is used as the point of rotation during mouse-interaction? How does the on screen arrow correspond to the normal of the cutplane scr.implicit_plane.normal? Thanks again, Chris _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev
Open this post in threaded view
|

## Re: Isosurface and cuts

 In reply to this post by Gael Varoquaux Hi again, > I am sorry, I don't understand. Are you saying that your data are located > on the same grid? In the expression above, i is not relevant in the loop. --->  Yes I just need #i copies of that. Again, my python-noobnes. > Granted, I was bullshitting. I wrote that last email too quickly. > What you want is: > > out = scp.cutter.outputs[0] > data = out.point_data.scalars.to_array() > > The points on which the data are located are: > > points = out.points.to_array() > > Sure, it's a mouthfull to work with, as they are not regularly spaced . > That kind of difficulties is what makes working with 3D data challenging. > So this is great, thank you very much! I got access to alle the relevant data I am interested in and now I am processing it. This raised some more questions. At first I tried to rotate the normal of the cut plane parallel to the z-axes, so I can make a 2d plot out of the data. Good thing is, a rotation takes place, but some things I do not understand: In what coordinate system is the normal given? How can I directly set the coordinates of this thick point that is used as the point of rotation during mouse-interaction? How does the on screen arrow correspond to the normal of the cutplane scr.implicit_plane.normal? Thanks again, Chris _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev
Open this post in threaded view
|

## Re: Isosurface and cuts

 In reply to this post by Gael Varoquaux Hi again, I apologize if this is just a stupid question, but I am a bit lost in all the possibilities mayavi offers. 1. Is it possible to hide the normal-arrow of a cut plane and hide everything of the data, that is above or below that cut plane? 2. How can I explicitly set the point of view of the camera? Thanks again, Chris _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev
Open this post in threaded view
|

## Re: Isosurface and cuts

 On Tue, Jan 31, 2012 at 2:12 PM, Christoph Piefke <[hidden email]> wrote: > Hi again, > > I apologize if this is just a stupid question, but I am a bit lost in > all the possibilities mayavi offers. > > 1. Is it possible to hide the normal-arrow of a cut plane and hide > everything of the data, that is above or below that cut plane? Yes, you can disable the widget. For example if you have a scalar_cut_plane, you can do : scalar_cut_plane.widget.enabled = False > 2. How can I explicitly set the point of view of the camera? This might help : http://github.enthought.com/mayavi/mayavi/auto/mlab_camera.html-- Didrik _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev
Open this post in threaded view
|

## Re: Isosurface and cuts

 > Yes, you can disable the widget. For example if you have a > scalar_cut_plane, you can do : > > scalar_cut_plane.widget.enabled = False > Thanks a lot, but I am doing something wrong:      mlab.pipeline.scalar_cut_plane(sgrid[2]).widget.enabled = False --> AttributeError: 'ScalarCutPlane' object has no attribute 'widget' >> 2. How can I explicitly set the point of view of the camera? > This might help : > http://github.enthought.com/mayavi/mayavi/auto/mlab_camera.html> It did! 3. Is this the way to go if I want to hide data above my scalar-cut-plane? http://github.enthought.com/mayavi/mayavi/auto/example_adjust_cropping_extents.html#example-adjust-cropping-extentsThanks, Chris _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev
Open this post in threaded view
|

## Re: Isosurface and cuts

 Le 31/01/2012 15:13, Christoph Piefke a écrit : > >> Yes, you can disable the widget. For example if you have a >> scalar_cut_plane, you can do : >> >> scalar_cut_plane.widget.enabled = False >> > Thanks a lot, but I am doing something wrong: >       mlab.pipeline.scalar_cut_plane(sgrid[2]).widget.enabled = False > > -->  AttributeError: 'ScalarCutPlane' object has no attribute 'widget' AFAIK, I would say scalar_cut_plane.implicit_plane.widget... -- Fred _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev
Open this post in threaded view
|

## Re: Isosurface and cuts

 > AFAIK, I would say scalar_cut_plane.implicit_plane.widget... > Ahaa, great :) it could have thought of that myself, but as I already mentioned, I am new to all that python and mayavi stuff. Thanks a lot :) _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev
Open this post in threaded view
|

## Re: Isosurface and cuts

 On Tue, Jan 31, 2012 at 3:23 PM, Christoph Piefke <[hidden email]> wrote: > >> AFAIK, I would say scalar_cut_plane.implicit_plane.widget... >> > Ahaa, great :) it could have thought of that myself, but as I already > mentioned, I am new to all that python and mayavi stuff. > Thanks a lot :) Thanks Fred! Went a bit fast to post ;-) -- Didrik _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev
Open this post in threaded view
|

## Re: Isosurface and cuts

 In reply to this post by Christoph Piefke On Mon, Jan 30, 2012 at 04:12:09PM +0100, Christoph Piefke wrote: > In what coordinate system is the normal given? I am not sure. > How can I directly set the coordinates of this thick point that is used > as the point of rotation during mouse-interaction? I can't tell out of the box. However, to answer these kind of questions, the record feature really helps: http://github.enthought.com/mayavi/mayavi/mlab.html#changing-object-properties-interactively> How does the on screen arrow correspond to the normal of the cutplane > scr.implicit_plane.normal? Not sure either: it's pretty hard to keep in one's head all the details of the VTK model. G _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev