[Insight-users] problem for ITKimage to VTKimage in managedITKin C# in Visual Studio 2008

Dan Mueller dan.mueller at philips.com
Mon Apr 7 02:20:50 EDT 2008


Hi Han,

I have looked into the problem and there seem to two issues:

1. The first issue is with the wrapping of GetOutput(..) in 
itk::ImageToVTKImageFilter for vtkDotNet. This method returns a *const* 
pointer instead of a non-const one (it passes true to the vtkImageData 
constructor instead of false). The const pointer can not be cast, 
resulting in the discussed exception. I will upload a new version of 
ManagedITK within the next few days which fixes this. In the meantime you 
can fix this in your local copy by editing 
ExternalProjects\VTK\managed_itkImageToVTKImageFilter.cmake

2. With the above fix the ApplicationException "Could not downcast pointer 
to native class" goes away. Calling vtkImageData.ToString() (the C# 
equivalent of Print) operates as expected, displaying the correct imported 
vtkImageData. However a new problem arises when *using* the resultant 
vtkImageData as an input. In your case the vtkImageViewer believes it has 
not received an inputs, even after calling SetInput(..). I am still 
investigating this issue. I believe it may have something to do with the 
fact that I compiled the vtkDotNet wrappers against a different version of 
VTK as the ManagedITK.VTK wrappers. I'll synchronise the versions and let 
you know if it does the trick.

In the meantime you can use the vtkImageImport filter to import a 
ManagedITK image to vtkDotNet. See:
    
http://public.kitware.com/pipermail/insight-users/2007-August/023278.html

HTH

Cheers, Dan

insight-users-bounces at itk.org wrote on 04/06/2008 11:40:42 PM:
> 
> Hi Han,
> 
> Please try invoking Print( std::cout ) (or its equivalent in C#)
> in i2v.GetOutput() just after you call i2v.Update(), and let us
> know what you get as output.
> 
> 
>     Thanks
> 
> 
>         Luis
> 
> 
> ------------------
> Han Chunlei wrote:
> > Hei, All,
> > 
> > 
> > 
> > I am a new user of ITK. I installed managedITK3.4.0.1 and tried to use 

> > it C# in visual studio 2008. I tried to transfer an image data from 
ITK 
> > to VTK using itkimagetovtkimagefilter. The problem is that I always 
get 
> > the wrong message like:
> > 
> > 
> > 
> > Warning: in ..\...\Code\common\itkProcessObject.cxx, line 520
> > 
> > ImagetoVTKimageFilter(04db21e0):Output doesn?t exist!
> > 
> > 
> > 
> > And debug information as:
> > 
> > ApplicationException was unhandled
> > 
> > Could not downcast pointer to native class
> > 
> > 
> > 
> > In the line of
> > 
> > View.SetInput(i2v.getOutput());
> > 
> > 
> > 
> > Any help is greatly appreciated.
> > 
> > 
> > 
> > Chunlei Han
> > 
> > 
> > 
> > 
> 
***************************************************************************************************
> > 
> > 
> > 
> > The codes are as follows:
> > 
> > using vtk;
> > 
> > using itk;
> > 
> > using itk2vtk = itk.itkImageToVTKImageFilter;
> > 
> > 
> > 
> >                       //  build an image
> > 
> >             itk.itkImage_UC2 itkimg = itk.itkImage_UC2.New();
> > 
> >             itk.itkSize itksz = new itk.itkSize(128, 128);
> > 
> >             itk.itkIndex itkind = new itk.itkIndex(0, 0);
> > 
> >             itk.itkImageRegion region = new 
> > itk.itkImageRegion(itksz,itkind);
> > 
> > 
> > 
> >             itkimg.SetRegions(region);
> > 
> >             itkimg.Allocate();
> > 
> >             itkimg.FillBuffer(128);
> > 
> > 
> > 
> >            // confirm the image
> > 
> >             string filename = @"c:\temp\test.jpg";
> > 
> >             itkimg.Write(filename);
> > 
> >             itk.itkImageInformation info = 
> > itk.itkImageBase.ReadInformation(filename);
> > 
> >             Console.WriteLine("infor= " + info.Size.ToString());
> > 
> > 
> > 
> >            // transfer itkImage to VTKimage by 
itkImagetoVTKimageFilter
> > 
> >             itk2vtk i2v = itk2vtk.New("IUC2");
> > 
> >             i2v.SetInput(itkimg);
> > 
> >             i2v.Update();
> > 
> >             vtk.vtkImageViewer viewer = new vtkImageViewer();
> > 
> >             viewer.SetInput(i2v.GetOutput()); // always problem here.


More information about the Insight-users mailing list