[Insight-users] How do I write a TCL-wrappable C++ function that will take an ITK image as an argument?
kent williams
nkwmailinglists at gmail.com
Fri Jun 26 11:56:14 EDT 2009
So we have this application BRAINSTracer (
http://www.nitrc.org/projects/brainstracer/ ) that primarily is
designed for using contours for manually tracing brain anatomy. We
have just integrated our BRAINS3 package of TCL functions (
http://www.nitrc.org/projects/brains/ ) into BRAINSTracer, which
allows us to write image processing scripts in TCL, mostly using ITK
filters.
In order to aid visualization, I added some wrapped methods to our
KWWidgets application so that TCL scripts can acquire handles on
images loaded in the GUI:
vtkImageData *GetActiveImage();
vtkImageData *GetImage(const char *imageName);
const char *GetImageNames();
void SetImage(vtkImageData *image,const char *name);
These methods work well as far as they go -- VTK wrapping seems to
handle parameter and return types of vtkImageData OK.
But there's an absurd chain of conversions that has to take place in
order for our TCL scripting code -- which works with ITK Images -- to
get images into and out of the Application's GUI. GetActiveImage
converts the internally stored ITK iimage to vtkImageData, returns it
to the TCL script which converts it back to an ITK Image. SetImage
requires the script to go the other direction: itk::Image ->
vtkImageData to call SetImage. Then the application class converts the
image back to an ITK image.
And of course, to actually display the image, the application converts
the ITK image back into vtkImageData.
This is a lot of to-ing and fro-ing! Plus it involves two completely
different wrapping methods -- KWWIdgets uses VTK wrapping, and ITK
uses its own wrapping.
What I'd like to know is what the method would be to directly accept
an ITK image as a parameter to a VTK-wrapped class method.
I'm suspecting it will end up being something as dreadful as this:
void SetImage(void *Image)
{
itk::ImageBase<3> *itkImage = reinterpret_cast<itk::ImageBase<3> >(image);
if( dynamic_cast<itk::Image<unsigned char, 3> >(itkImage) != 0)
{
...
}
else if(dynamic_cast<itk::Image<char,3> >(itkImage) != 0)
{
...
}
//etc etc etc
}
More information about the Insight-users
mailing list