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

Prathamesh Kulkarni prathameshmkulkarni at gmail.com
Fri Oct 22 13:34:04 EDT 2010


If I change that, I get the following error:
error C2440: 'type cast' : cannot convert from 'void *' to
'itk::SmartPointer<TObjectType>'
1>        with
1>        [
1>            TObjectType=itk::Image<PixelType,2>
1>        ]
1>        No constructor could take the source type, or constructor overload
resolution was ambiguous

Using the function is not justified per se, but I am also no able to figure
out where I am going wrong.

- Prathamesh

On Fri, Oct 22, 2010 at 11:52 AM, David Doria <daviddoria at gmail.com> wrote:

> 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/ae2a4ed9/attachment.htm>


More information about the Insight-users mailing list