[vtkusers] Voxel Data from MATLAB to VTK
Otahal, Thomas
tjotaha at sandia.gov
Mon May 17 15:39:58 EDT 2010
Hello,
I am the main developer of the Matlab Engine related code in VTK.
Yes, vtkMatlabMexAdapter is the class you need to convert data from VTK to the Matlab mxArray type and back again. This class will get compiled when VTK_USE_MATLAB_MEX is turned on in the Cmake advanced options of VTK.
The documentation located on the Infovis Wiki regarding Matlab is very out of date and needs to be revised. Sorry for any confusion.
Are you are trying to build a Matlab mex program (shared library) that takes input Matlab data and sends it to VTK, and then returns data from VTK to Matlab?
--Tom
On 5/17/10 12:44 PM, "David Gobbi" <david.gobbi at gmail.com> wrote:
My familiarity with Titan is nil, but "git blame" tells me that the
vtkMatlabMexAdapter.h has been in VTK since 2009-12-14. It should be
built whenever VTK_USE_MATLAB_MEX is turned ON in CMake.
I haven't ever used the new VTK matlab engine stuff, so hopefully
someone that is familiar with it will chime in.
David
On Mon, May 17, 2010 at 12:29 PM, Brian Davis <bitminer at gmail.com> wrote:
> The latest I found suports using flat arrays as you suggest and as I tried
> to do and reshaping with and example I found at:
>
> http://www.kitware.com/InfovisWiki/index.php/Matlab_Interface
>
> The vtkMatlabMexAdapter looks exactly like what I am looking for
>
> --snip
>
> edata =
> vtkMatlabMexAdapter::mxArrayTovtkDataArray(const_cast<mxArray*>(prhs[0]));
>
> id->SetDimensions(300,300,1);
> id->SetOrigin(0.0,0.0,0.0);
> id->SetSpacing(1.0,1.0,1.0);
> id->SetScalarTypeToUnsignedChar();
> id->SetNumberOfScalarComponents(3);
> id->SetWholeExtent(0,299,0,299,0,0);
>
> id->GetPointData()->SetScalars(edata);
>
> --end snip--
>
> However a search in my tree vtkMatlabMexAdapter returns nothing. Seems to
> be a part of Titan?
>
> Though it looks as thought it is in latest:
>
> http://www.vtk.org/doc/nightly/html/classvtkMatlabMexAdapter.html
>
>
> Brian
>
>
> On Mon, May 17, 2010 at 11:25 AM, David Gobbi <david.gobbi at gmail.com> wrote:
>>
>> Hi Brian,
>>
>> It's much easier to use flat arrays to store n-dimensional data in
>> VTK. This is how VTK manages structured data such as vtkImageData.
>> Then all you need to do when moving the data into Matlab is reshape
>> the flat array into an n-dimensional array by using the known
>> dimensions of the desired n-dimensional array.
>>I
>> For example, when moving vtkImageData to Python's NumPy, I grab the
>> Dimensions and NumberOfScalarComponents from the image data and use
>> that information to reshape the array into a 3D or 4D array. The same
>> could be done with Matlab, I think.
>>
>> David
>>
>>
>> On Mon, May 17, 2010 at 10:15 AM, Brian Davis <bitminer at gmail.com> wrote:
>> > So latest in my search for how to do this I came across:
>> >
>> > http://www.vtk.org/doc/nightly/html/classvtkArrayData.html
>> >
>> > With the important part:
>> >
>> > --snip--
>> > Because vtkArray cannot be stored as attributes of data objects (yet), a
>> > "carrier" object is needed to pass vtkArray through the pipeline.
>> > vtkArrayData acts as a container of zero-to-many vtkArray instances,
>> > which
>> > can be retrieved via a zero-based index. Note that a collection of
>> > arrays
>> > stored in vtkArrayData may-or-may-not have related types, dimensions,
>> > or
>> > extents.
>> > --end snip--
>> >
>> > and looking at the api and input types for ImageData and the
>> > volumeMappers
>> > the input to these appears to only be a route that involves vtkDataSet.
>> > I
>> > get the feeling that using the Array classes in an attempt to create
>> > image
>> > data is an futile attempt at "round hole square plug" am I correct with
>> > this
>> > assessment? Array data appears to have a path to filters and not image
>> > data. Is this correct?
>> >
>> > Which means I may have to result to awful for loops as in the examples.
>> > I
>> > also looked at the examples for
>> >
>> > Brian
>> >
>> > _______________________________________________
>> > Powered by www.kitware.com
>> >
>> > Visit other Kitware open-source projects at
>> > http://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
>> >
>> >
>
>
>
> --
> Brian J. Davis
>
>
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at http://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/20100517/c93f516a/attachment.htm>
More information about the vtkusers
mailing list