[Insight-users] [vtkusers] cannot return output of itk::ImageToVTKImageFilter

David Doria daviddoria at gmail.com
Fri Oct 22 12:52:01 EDT 2010


On Fri, Oct 22, 2010 at 12:44 PM, Prathamesh Kulkarni <
prathameshmkulkarni at gmail.com> wrote:

>
> Hello all,
>
> I am converting an ITK image to VTK image and rendering it. However, I am
> not able to return the filter's output from the function which does the
> conversion. Following is a code snippet.
>
> vtkSmartPointer<vtkImageData> convertITKImageToVTKImage(void
> *itk_img_void_ptr){
>     typedef float PixelType;
>     const unsigned int dimensions = 2;
>     typedef itk::Image<PixelType, dimensions> ImageType;
>
>     ImageType::Pointer itk_img = ImageType::New();
>     ImageType::Pointer *itk_img_ptr =
> (ImageType::Pointer*)itk_img_void_ptr;
>     itk_img = itk_img_ptr->GetPointer();
>
>     typedef itk::ImageToVTKImageFilter<ImageType> ITKToVTKFilterType;
>     ITKToVTKFilterType::Pointer ITK_to_VTK_filter =
> ITKToVTKFilterType::New();
>
>     ITK_to_VTK_filter->SetInput(itk_img);
>     ITK_to_VTK_filter->Update();
>
>     vtkSmartPointer<vtkImageData> vtk_image =
> ITK_to_VTK_filter->GetOutput();
>     //vtk_image->Update();
>
>     //uncomment to test.. THIS RENDERING WORKS
>     renderImage(castImage(vtk_image, std::string("unsigned char")), true);
>
>     return vtk_image;
> }
>
> void foo(){
>     vtkSmartPointer<vtkImageData> BScan_vtk_image =
> convertITKImageToVTKImage(itk_image_void_ptr);
>
>     //THIS RENDERING FAILS - ERROR: unhandled exception at
> itkVTKImageExportBase.cxx
>     renderImage(OCTCommon::castImage(BScan_vtk_image, std::string("unsigned
> char")), true);
> }
>
>
> Please point me out, where am I going wrong?
>

The ::Pointer member is already a pointer, so there should be no need for
the '*'. That is, change

 ImageType::Pointer *itk_img_ptr = (ImageType::Pointer*)itk_img_void_ptr;

to

 ImageType::Pointer itk_img_ptr = (ImageType::Pointer)itk_img_void_ptr;

Here is a demo of ImageToVTKImageFilter
http://www.itk.org/Wiki/ITK/Examples/ItkVtkGlue/ImageToVTKImageFilter

I'm not sure I follow why you need your own function, isn't this conversion
exactly what this filter does?
<http://www.itk.org/Wiki/ITK/Examples/ItkVtkGlue/ImageToVTKImageFilter>

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20101022/80cf3167/attachment.htm>


More information about the Insight-users mailing list