Path: news.mathworks.com!not-for-mail
From: "Phil Goddard" <philgoddardNOSPAM@telus.net>
Newsgroups: comp.soft-sys.matlab
Subject: Re: is MATLAB GUI + vtk renderer possible?
Date: Thu, 19 Feb 2009 16:36:01 +0000 (UTC)
Organization: Goddard Consulting
Lines: 27
Message-ID: <gnk1ph$nf2$1@fred.mathworks.com>
References: <gaoeef$64a$1@fred.mathworks.com> <gnjj4p$nqf$1@fred.mathworks.com>
Reply-To: "Phil Goddard" <philgoddardNOSPAM@telus.net>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1235061361 24034 172.30.248.38 (19 Feb 2009 16:36:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 19 Feb 2009 16:36:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 26433
Xref: news.mathworks.com comp.soft-sys.matlab:519491



The easiest approach to incorporating VTK into a MATLAB figure window is to use the ActiViz COM object available from www.kitware.com.
(KitWare are the people who write/maintain the core VTK code.)
It is a fully functional COM interface into VTK and can easily be instantated in MATLAB using the function actxcontrol.
Unfortunately it is only compiled for win32, and does cost (about $4000 if I remember correctly).

There are a couple of other alternatives for calling VTK from MATLAB, none of them currently allow for embedding the VTK renderer into a figure window, but with a little effort a lot can be done by using a "2 window" approach: visualization rendering performed in a VTK window with other UI functionality in a MATLAB figure/UI. 

- writing a mex file that calls your VTK code.
This is described in the link posted in this thread, and there's also a mex file example on the File Exchange (just search it for VTK).

- writing your own COM object called from MATLAB using actxserver.
(I have found this particularly useful when you need the same code to work from not just MATLAB but also from other C code and FORTRAN, and also on different platforms like win32, win64, linux, etc.)
With enough effort this could be extended to become a COM control embeddable in a figure window but I have not done that.

And for the future, but again at a price:
- Kitware have recently released a (multi-platform) .NET version of their COM object.
Hopefully it won't be long before these can be called directly from MATLAB in a similar way to the way that generic dlls can be called now.

As for Greg's question about why to go to VTK, I went there for 2 reasons:
- I have some images that cannot be efficiently rotated when displayed in a MATLAB figure window.
(In VTK when the mouse is moved the images smoothly rotate.
In MATLAB when the mouse is moved the image rotates a couple of degrees then redraws, moves a couple more degrees then redraws, etc, etc, making for "chunky graphics".
I sent an example to MathWorks tech support and they don't believe it can be done any faster in MATLAB.)
- I was doing the work for a consulting client who needed to call the same graphics from not just MATLAB but also C and FORTRAN.

Phil.