[vtkusers] FW: vtk dataset import

Eric E. Monson emonson at cs.duke.edu
Thu Jan 21 13:08:27 EST 2010


Hey Ryan,

Maybe someone else will have a better suggestion, but when I need to view Matlab data using VTK classes, I work in python. If you haven't used python then the following will probably be gibberish, but...

The scipy.io.loadmat() function can read old (pre-v7.3) .mat files into structures that contain numpy arrays. If you're using the newer HDF5-based .mat file format, then pytables can navigate through the hierarchical file and read in (numpy) arrays. 

VTK has support for converting both directions between numpy arrays and VTK data arrays (vtkIntArray, vtkFloatArray, etc) in vtk.util.numpy_support [numpy_to_vtk() & vtk_to_numpy()]. You can then build whatever type of vtkDataSet you need (vtkImageData, maybe?) right there in python and assign the values you've read from your matlab arrays as attributes of the VTK structure and start building your VTK visualization pipeline from there.

Otherwise, your best bet may be to try to write your data out from Matlab as an ascii-format legacy VTK file, or some other format VTK can read natively, and load that file directly into your VTK pipeline.

Hope this helps. If you need a C++ solution for reading Matlab files someone else will have to chime in.

-Eric
 
------------------------------------------------------
Eric E Monson
Duke Visualization Technology Group


On Jan 20, 2010, at 6:53 AM, Ryan Bloor wrote:

> 
>  
> From: ryanbloor at hotmail.com
> To: vtkusers at vtk.org
> Subject: vtk dataset import
> Date: Wed, 20 Jan 2010 11:30:19 +0000
> 
> Hello, 
> 
> I am wondering whether VTK provides functionality to read in .mat dataset files. I currently have three files corresponding to the three primary eigenvectors and would like to load them into VTK and view some 2D slices to make sure it has worked. The data files are quite large so I cannot upload them unfortunately. 
> 
> Any help and guidance would be great, 
> 
> Thanks 
> 
> Do you have a story that started on Hotmail? Tell us now 
> We want to hear all your funny, exciting and crazy Hotmail stories. Tell us now _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects athttp://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the VTK FAQ at:http://www.vtk.org/Wiki/VTK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100121/b2d5fd9a/attachment.htm>


More information about the vtkusers mailing list