mayavi scalar_field

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

mayavi scalar_field

M Trumpis
Hey list,

I thought I had understood the use of the x,y,z grids in constructing
an MArraySource through "scalar_field(x,y,z,s)". I thought if you had
regularly sampled data in a 3 dimensional array, then the x,y,z arrays
would describe where the (possibly rotated) grid lies in a coordinate
system. (Could have sworn I successfully did this before) But looking
closer, it seems that the grid axes are restricted to being parallel
with the coordinate axes.

Do I have this right? If so, is there a way to position the data in
the scene without having to regrid data?

Mike
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: mayavi scalar_field

M Trumpis
to follow up.. I did find the StructuredGrid type which accepts
point-by-point locations, but I'm still trying to find a good way to
slice into it. Is there any way to "coerce" this into an ImageData
type?

Thanks

Mike

On Thu, Feb 25, 2010 at 5:38 PM, M Trumpis <[hidden email]> wrote:

> Hey list,
>
> I thought I had understood the use of the x,y,z grids in constructing
> an MArraySource through "scalar_field(x,y,z,s)". I thought if you had
> regularly sampled data in a 3 dimensional array, then the x,y,z arrays
> would describe where the (possibly rotated) grid lies in a coordinate
> system. (Could have sworn I successfully did this before) But looking
> closer, it seems that the grid axes are restricted to being parallel
> with the coordinate axes.
>
> Do I have this right? If so, is there a way to position the data in
> the scene without having to regrid data?
>
> Mike
>
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: mayavi scalar_field

Gael Varoquaux
In reply to this post by M Trumpis
On Thu, Feb 25, 2010 at 05:38:46PM -0800, M Trumpis wrote:
> I thought I had understood the use of the x,y,z grids in constructing
> an MArraySource through "scalar_field(x,y,z,s)". I thought if you had
> regularly sampled data in a 3 dimensional array, then the x,y,z arrays
> would describe where the (possibly rotated) grid lies in a coordinate
> system. (Could have sworn I successfully did this before) But looking
> closer, it seems that the grid axes are restricted to being parallel
> with the coordinate axes.

Yes unfortunately that's exactly it. The spacing of the grid can be
changed independently in all directly, but you can't change the
orientation.

> Do I have this right? If so, is there a way to position the data in
> the scene without having to regrid data?

There is no simple and satisfactory way.

I think I know what you are trying to do. I was discussing about this we
Pierre Fillard, of MedInria fame, who knows VTK very well. He says that
the best way to do this is to rotate the actor. The problem when you do
this is that the data hasn't been rotated, and thus when applying new
module to the data, you need to rotate them as well.

So, ImageData cannot be in diagonal. As you point out in a later email,
StructuredGrid can, but you have to slice it with a 'ScalarCutPlane'
which is much slower than the ImagePlaneWidget. You cannot 'Coerce it
into an ImageData without sampling it to a non diagonal grid. However, if
you want to do this, the 'ImageDataProbe', called 'Probe on image data'
in the filter menu of Mayavi, should do the trick.

HTH,

Gaël
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: mayavi scalar_field

M Trumpis
On Thu, Feb 25, 2010 at 10:22 PM, Gael Varoquaux
<[hidden email]> wrote:

> On Thu, Feb 25, 2010 at 05:38:46PM -0800, M Trumpis wrote:
>> I thought I had understood the use of the x,y,z grids in constructing
>> an MArraySource through "scalar_field(x,y,z,s)". I thought if you had
>> regularly sampled data in a 3 dimensional array, then the x,y,z arrays
>> would describe where the (possibly rotated) grid lies in a coordinate
>> system. (Could have sworn I successfully did this before) But looking
>> closer, it seems that the grid axes are restricted to being parallel
>> with the coordinate axes.
>
> Yes unfortunately that's exactly it. The spacing of the grid can be
> changed independently in all directly, but you can't change the
> orientation.
>
>> Do I have this right? If so, is there a way to position the data in
>> the scene without having to regrid data?
>
> There is no simple and satisfactory way.
>
> I think I know what you are trying to do. I was discussing about this we
> Pierre Fillard, of MedInria fame, who knows VTK very well. He says that
> the best way to do this is to rotate the actor. The problem when you do
> this is that the data hasn't been rotated, and thus when applying new
> module to the data, you need to rotate them as well.
>
> So, ImageData cannot be in diagonal. As you point out in a later email,
> StructuredGrid can, but you have to slice it with a 'ScalarCutPlane'
> which is much slower than the ImagePlaneWidget. You cannot 'Coerce it
> into an ImageData without sampling it to a non diagonal grid. However, if
> you want to do this, the 'ImageDataProbe', called 'Probe on image data'
> in the filter menu of Mayavi, should do the trick.
>

This is great! It did work, except the dimensions for the filter seem
to be calculated wrong starting off, giving this VTK error:

ERROR: In ../../Filtering/vtkStreamingDemandDrivenPipeline.cxx, line 818
vtkStreamingDemandDrivenPipeline (0x216d7480): The update extent
specified in the information for output port 0 on algorithm
vtkAssignAttribute(0x216d3130) is 0 0 0 96 0 60, which is outside the
whole extent 0 93 0 89 0 66.

When I change the ImageDataProbe dimensions to be the dimensions of
the input array, then the filter behaves. I managed to cut it with a
ImagePlaneWidget, and all was looking positive. The big question is
whether this was faster than other resampling solutions.

I had another problem, which I never solved but did work around. The
following sequence of commands fail with another VTK error (pasted
further below). I get back a filter that seems uninitialized. However,
if I add something like a structured_grid_outline to the pipeline
before creating the ImageDataProbe filter, then I'm back in business
(at least to the point above, with the wrong dimensions). So what's
changes when I add a vis module to the data first?

r = tvtk.StructuredGrid(dimensions=map_img.shape)
r.points = xyz_coords
r.point_data.scalars = np.asarray(map_img).flatten().copy()
md = mlab.pipeline.add_dataset(r)
idp = mlab.pipeline.image_data_probe(md)

ERROR: In ../../Graphics/vtkAssignAttribute.cxx, line 276
vtkAssignAttribute (0x22a45040): Data must be point or cell for vtkDataSet

ERROR: In ../../Filtering/vtkExecutive.cxx, line 757
vtkStreamingDemandDrivenPipeline (0x2564ed30): Algorithm
vtkAssignAttribute(0x22a45040) returned failure for request:
vtkInformation (0x25679440)
  Debug: Off
  Modified Time: 812531
  Reference Count: 1
  Registered Events: (none)
  Request: REQUEST_DATA
  FROM_OUTPUT_PORT: 0
  FORWARD_DIRECTION: 0
  ALGORITHM_AFTER_FORWARD: 1

Many thanks

Mike
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: mayavi scalar_field

Gael Varoquaux
On Fri, Feb 26, 2010 at 01:14:07AM -0800, M Trumpis wrote:
> > So, ImageData cannot be in diagonal. As you point out in a later email,
> > StructuredGrid can, but you have to slice it with a 'ScalarCutPlane'
> > which is much slower than the ImagePlaneWidget. You cannot 'Coerce it
> > into an ImageData without sampling it to a non diagonal grid. However, if
> > you want to do this, the 'ImageDataProbe', called 'Probe on image data'
> > in the filter menu of Mayavi, should do the trick.


> This is great! It did work, except the dimensions for the filter seem
> to be calculated wrong starting off, giving this VTK error:

> ERROR: In ../../Filtering/vtkStreamingDemandDrivenPipeline.cxx, line 818
> vtkStreamingDemandDrivenPipeline (0x216d7480): The update extent
> specified in the information for output port 0 on algorithm
> vtkAssignAttribute(0x216d3130) is 0 0 0 96 0 60, which is outside the
> whole extent 0 93 0 89 0 66.

OK, that's probably something that we can fix. I'll try and have a look
at the code of the ImageDataProbe when I have time (unless you beat me to
it, of course).

> When I change the ImageDataProbe dimensions to be the dimensions of
> the input array, then the filter behaves. I managed to cut it with a
> ImagePlaneWidget, and all was looking positive. The big question is
> whether this was faster than other resampling solutions.

Time it :). I should be pretty fast, VTK is well coded.

> I had another problem, which I never solved but did work around. The
> following sequence of commands fail with another VTK error (pasted
> further below). I get back a filter that seems uninitialized. However,
> if I add something like a structured_grid_outline to the pipeline
> before creating the ImageDataProbe filter, then I'm back in business
> (at least to the point above, with the wrong dimensions). So what's
> changes when I add a vis module to the data first?

> r = tvtk.StructuredGrid(dimensions=map_img.shape)
> r.points = xyz_coords
> r.point_data.scalars = np.asarray(map_img).flatten().copy()
> md = mlab.pipeline.add_dataset(r)
> idp = mlab.pipeline.image_data_probe(md)

OK, I suspect that it is a pipelining bug. Can you try to add:

    md.update_pipeline()

before the image_data_probe.

If this doesn't solve the problem, can you send me a minimal example (I
am too lazy to code one), and I'll have a look.

Gaël
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: mayavi scalar_field

M Trumpis
Hey,

On Fri, Feb 26, 2010 at 2:13 AM, Gael Varoquaux
<[hidden email]> wrote:

> On Fri, Feb 26, 2010 at 01:14:07AM -0800, M Trumpis wrote:
>> > So, ImageData cannot be in diagonal. As you point out in a later email,
>> > StructuredGrid can, but you have to slice it with a 'ScalarCutPlane'
>> > which is much slower than the ImagePlaneWidget. You cannot 'Coerce it
>> > into an ImageData without sampling it to a non diagonal grid. However, if
>> > you want to do this, the 'ImageDataProbe', called 'Probe on image data'
>> > in the filter menu of Mayavi, should do the trick.
>
>
>> This is great! It did work, except the dimensions for the filter seem
>> to be calculated wrong starting off, giving this VTK error:
>
>> ERROR: In ../../Filtering/vtkStreamingDemandDrivenPipeline.cxx, line 818
>> vtkStreamingDemandDrivenPipeline (0x216d7480): The update extent
>> specified in the information for output port 0 on algorithm
>> vtkAssignAttribute(0x216d3130) is 0 0 0 96 0 60, which is outside the
>> whole extent 0 93 0 89 0 66.
>
> OK, that's probably something that we can fix. I'll try and have a look
> at the code of the ImageDataProbe when I have time (unless you beat me to
> it, of course).
>

I've given it a look (in _setup_probe_data(), unless I'm mistaken). So
in this filter we're creating a new ImageData object with the grid
aligned on the spatial axes. I don't know the underlying filter
mechanics, but one would think that the extents and dimension sizes
may be different for the input and output data. Maybe this is a case
of making an initial assumption about the output dimension extents,
and failing to update it later?


>> When I change the ImageDataProbe dimensions to be the dimensions of
>> the input array, then the filter behaves. I managed to cut it with a
>> ImagePlaneWidget, and all was looking positive. The big question is
>> whether this was faster than other resampling solutions.
>
> Time it :). I should be pretty fast, VTK is well coded.
>
>> I had another problem, which I never solved but did work around. The
>> following sequence of commands fail with another VTK error (pasted
>> further below). I get back a filter that seems uninitialized. However,
>> if I add something like a structured_grid_outline to the pipeline
>> before creating the ImageDataProbe filter, then I'm back in business
>> (at least to the point above, with the wrong dimensions). So what's
>> changes when I add a vis module to the data first?
>
>> r = tvtk.StructuredGrid(dimensions=map_img.shape)
>> r.points = xyz_coords
>> r.point_data.scalars = np.asarray(map_img).flatten().copy()
>> md = mlab.pipeline.add_dataset(r)
>> idp = mlab.pipeline.image_data_probe(md)
>
> OK, I suspect that it is a pipelining bug. Can you try to add:
>
>    md.update_pipeline()
>
> before the image_data_probe.
>

Actually, md is

In [23]: md
Out[23]: <enthought.mayavi.sources.vtk_data_source.VTKDataSource
object at 0x20cef9c0>

and doesn't have an update_pipeline() member. Is there another way to do it?

Kind regards,

Mike

> If this doesn't solve the problem, can you send me a minimal example (I
> am too lazy to code one), and I'll have a look.
>
> Gaël
> _______________________________________________
> 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
Reply | Threaded
Open this post in threaded view
|

Re: mayavi scalar_field

Gael Varoquaux
On Sun, Feb 28, 2010 at 05:06:07PM -0800, M Trumpis wrote:
> > On Fri, Feb 26, 2010 at 01:14:07AM -0800, M Trumpis wrote:
> >> > So, ImageData cannot be in diagonal. As you point out in a later email,
> >> > StructuredGrid can, but you have to slice it with a 'ScalarCutPlane'
> >> > which is much slower than the ImagePlaneWidget. You cannot 'Coerce it
> >> > into an ImageData without sampling it to a non diagonal grid. However, if
> >> > you want to do this, the 'ImageDataProbe', called 'Probe on image data'
> >> > in the filter menu of Mayavi, should do the trick.


> >> This is great! It did work, except the dimensions for the filter seem
> >> to be calculated wrong starting off, giving this VTK error:

> >> ERROR: In ../../Filtering/vtkStreamingDemandDrivenPipeline.cxx, line 818
> >> vtkStreamingDemandDrivenPipeline (0x216d7480): The update extent
> >> specified in the information for output port 0 on algorithm
> >> vtkAssignAttribute(0x216d3130) is 0 0 0 96 0 60, which is outside the
> >> whole extent 0 93 0 89 0 66.

> > OK, that's probably something that we can fix. I'll try and have a look
> > at the code of the ImageDataProbe when I have time (unless you beat me to
> > it, of course).


> I've given it a look (in _setup_probe_data(), unless I'm mistaken). So
> in this filter we're creating a new ImageData object with the grid
> aligned on the spatial axes. I don't know the underlying filter
> mechanics, but one would think that the extents and dimension sizes
> may be different for the input and output data. Maybe this is a case
> of making an initial assumption about the output dimension extents,
> and failing to update it later?

Sounds plausible. That's probably the sort of thing that should be
updated on update_data.

> >> I had another problem, which I never solved but did work around. The
> >> following sequence of commands fail with another VTK error (pasted
> >> further below). I get back a filter that seems uninitialized. However,
> >> if I add something like a structured_grid_outline to the pipeline
> >> before creating the ImageDataProbe filter, then I'm back in business
> >> (at least to the point above, with the wrong dimensions). So what's
> >> changes when I add a vis module to the data first?

> >> r = tvtk.StructuredGrid(dimensions=map_img.shape)
> >> r.points = xyz_coords
> >> r.point_data.scalars = np.asarray(map_img).flatten().copy()
> >> md = mlab.pipeline.add_dataset(r)
> >> idp = mlab.pipeline.image_data_probe(md)

> > OK, I suspect that it is a pipelining bug. Can you try to add:

> >    md.update_pipeline()

> > before the image_data_probe.


> Actually, md is

> In [23]: md
> Out[23]: <enthought.mayavi.sources.vtk_data_source.VTKDataSource
> object at 0x20cef9c0>

> and doesn't have an update_pipeline() member. Is there another way to do it?

Does it have an update_data()? or a render? Try these.

Gaël
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: mayavi scalar_field

M Trumpis
On Sun, Feb 28, 2010 at 10:04 PM, Gael Varoquaux
<[hidden email]> wrote:

> On Sun, Feb 28, 2010 at 05:06:07PM -0800, M Trumpis wrote:
>> > On Fri, Feb 26, 2010 at 01:14:07AM -0800, M Trumpis wrote:
>> >> > So, ImageData cannot be in diagonal. As you point out in a later email,
>> >> > StructuredGrid can, but you have to slice it with a 'ScalarCutPlane'
>> >> > which is much slower than the ImagePlaneWidget. You cannot 'Coerce it
>> >> > into an ImageData without sampling it to a non diagonal grid. However, if
>> >> > you want to do this, the 'ImageDataProbe', called 'Probe on image data'
>> >> > in the filter menu of Mayavi, should do the trick.
>
>
>> >> This is great! It did work, except the dimensions for the filter seem
>> >> to be calculated wrong starting off, giving this VTK error:
>
>> >> ERROR: In ../../Filtering/vtkStreamingDemandDrivenPipeline.cxx, line 818
>> >> vtkStreamingDemandDrivenPipeline (0x216d7480): The update extent
>> >> specified in the information for output port 0 on algorithm
>> >> vtkAssignAttribute(0x216d3130) is 0 0 0 96 0 60, which is outside the
>> >> whole extent 0 93 0 89 0 66.
>
>> > OK, that's probably something that we can fix. I'll try and have a look
>> > at the code of the ImageDataProbe when I have time (unless you beat me to
>> > it, of course).
>
>
>> I've given it a look (in _setup_probe_data(), unless I'm mistaken). So
>> in this filter we're creating a new ImageData object with the grid
>> aligned on the spatial axes. I don't know the underlying filter
>> mechanics, but one would think that the extents and dimension sizes
>> may be different for the input and output data. Maybe this is a case
>> of making an initial assumption about the output dimension extents,
>> and failing to update it later?
>
> Sounds plausible. That's probably the sort of thing that should be
> updated on update_data.
>
>> >> I had another problem, which I never solved but did work around. The
>> >> following sequence of commands fail with another VTK error (pasted
>> >> further below). I get back a filter that seems uninitialized. However,
>> >> if I add something like a structured_grid_outline to the pipeline
>> >> before creating the ImageDataProbe filter, then I'm back in business
>> >> (at least to the point above, with the wrong dimensions). So what's
>> >> changes when I add a vis module to the data first?
>
>> >> r = tvtk.StructuredGrid(dimensions=map_img.shape)
>> >> r.points = xyz_coords
>> >> r.point_data.scalars = np.asarray(map_img).flatten().copy()
>> >> md = mlab.pipeline.add_dataset(r)
>> >> idp = mlab.pipeline.image_data_probe(md)
>
>> > OK, I suspect that it is a pipelining bug. Can you try to add:
>
>> >    md.update_pipeline()
>
>> > before the image_data_probe.
>
>
>> Actually, md is
>
>> In [23]: md
>> Out[23]: <enthought.mayavi.sources.vtk_data_source.VTKDataSource
>> object at 0x20cef9c0>
>
>> and doesn't have an update_pipeline() member. Is there another way to do it?
>
> Does it have an update_data()? or a render? Try these.

Yep.. render() is there and it worked to update the pipeline. Then, as
before, just a matter of changing the ImageDataProbe's dimension.

Mike


>
> Gaël
> _______________________________________________
> 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