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