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