[vtkusers] Reslicing vector data

David Gobbi dgobbi at atamai.com
Tue Feb 14 10:24:28 EST 2006


Hi Ed,

The vtkImageReslice filter only works on the scalars in the data, I 
think that all the Imaging filters are the same way.  You can fool it 
into operating on vectors by converting the vectors into a 
multi-component scalar array.  This probably won't give you want you 
want, though, because proper resampling of a vector grid involves more 
than just resampling the three components.

In order to properly resample a vector grid, you need to know what kind 
of vectors you are dealing with.  Vectors come in three flavors:

1) contravariant vectors: what you get by taking the derivative of x,y,z 
with respect to so something, e.g. velocity, acceleration

2) covariant vectors: what you get by taking the derivative of something 
with respect to x,y,z, e.g. a gradient

3) vectors that are mathematically unrelated to x,y,z, e.g. vectors that 
express RGB colors.

The only type of vector grid that vtkImageReslice will properly resample 
is type (3).  With the other two types, you have to rotate the vectors 
after you do the resampling in order to get the correct result.

 - David


Ed B wrote:

>
> Greetings,
>
> I am having trouble finding the best way to perform this operation. 
> The data originally resides in two float arrays, either in two fields 
> of the same data file or in two separate files. I have attempted two 
> different methods.
>
>
> Method 1: create vector data, then reslice
>
>     data = vtk.vtkImageData()
>     data.SetDimensions(dims[0],dims[1], 1)        
>     data.SetExtent(0, dims[0]-1, 0, dims[1]-1, 0, 0)
>     data.SetWholeExtent (0, dims[0]-1, 0, dims[1]-1, 0, 0)
>     data.SetOrigin(0,0,0)
>     data.GetPointData().SetVectors(array)
>     data.GetPointData().SetActiveVectors('vectors')
>
>     # Remap the data
>     x_dim = [0,1,0]
>     y_dim = [1,0,0]
>     z_dim = [0,0,1]
>     reslice = vtk.vtkImageReslice()
>     reslice.SetResliceAxesDirectionCosines(x_dim, y_dim, z_dim)
>     reslice.SetInput(data)
>     reslice.Update()
>
> This results in a dataset with only one scalar field, however.
>
> Method 2: reslice, then create vector data
>
> As a first experiment for this method, I tried simply composing vector 
> data from existing fields in a VTK dataset...
>
>     mf = vtk.vtkMergeFields()
>     mf.SetInput (data)
>     mf.SetOutputField('vectors', 'POINT_DATA')
>     mf.SetNumberOfComponents(2)
>     mf.Merge(0, 'uComponent', 0)
>     mf.Merge(1, 'vComponent', 0)
>     mf.Merge(2, 'vComponent', 0)   
>     mf.Update ()
>     mf.GetOutput().GetPointData().GetArray('vectors').FillComponent(2,0.0)
>     
> mf.GetOutput().GetPointData().SetVectors(mf.GetOutput().GetPointData().GetArray('vectors'))
>     mf.GetOutput().GetPointData().SetActiveVectors('vectors')
>
> Somehow, I'm unable to get the new array 'vectors' to appear in the 
> vectors section when I print mf.GetOutput()
>
> So, I'm wondering... is there a better way to go about this? There's 
> always the brute force way of iterating over the components after the 
> reslice to create the vector array, but I'm hoping for a more 
> efficient solution.
>
> - Ed
>
>------------------------------------------------------------------------
>
>_______________________________________________
>This is the private VTK discussion list. 
>Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>Follow this link to subscribe/unsubscribe:
>http://www.vtk.org/mailman/listinfo/vtkusers
>  
>




More information about the vtkusers mailing list