<div><div><div class="gmail_quote">On Fri, Oct 22, 2010 at 12:44 PM, Prathamesh Kulkarni <span dir="ltr"><<a href="mailto:prathameshmkulkarni@gmail.com">prathameshmkulkarni@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div dir="ltr"><br>Hello all,<br><br>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.<br>
<br>vtkSmartPointer<vtkImageData> convertITKImageToVTKImage(void *itk_img_void_ptr){<br> typedef float PixelType;<br> const unsigned int dimensions = 2;<br> typedef itk::Image<PixelType, dimensions> ImageType;<br>
<br> ImageType::Pointer itk_img = ImageType::New();<br> ImageType::Pointer *itk_img_ptr = (ImageType::Pointer*)itk_img_void_ptr;<br> itk_img = itk_img_ptr->GetPointer();<br><br> typedef itk::ImageToVTKImageFilter<ImageType> ITKToVTKFilterType;<br>
ITKToVTKFilterType::Pointer ITK_to_VTK_filter = ITKToVTKFilterType::New();<br><br> ITK_to_VTK_filter->SetInput(itk_img);<br> ITK_to_VTK_filter->Update();<br><br> vtkSmartPointer<vtkImageData> vtk_image = ITK_to_VTK_filter->GetOutput();<br>
//vtk_image->Update();<br> <br> //uncomment to test.. THIS RENDERING WORKS<br> renderImage(castImage(vtk_image, std::string("unsigned char")), true);<br><br> return vtk_image;<br>}<br><br>void foo(){<br>
vtkSmartPointer<vtkImageData> BScan_vtk_image = convertITKImageToVTKImage(itk_image_void_ptr);<br> <br> //THIS RENDERING FAILS - ERROR: unhandled exception at itkVTKImageExportBase.cxx <br> renderImage(OCTCommon::castImage(BScan_vtk_image, std::string("unsigned char")), true); <br>
}<br><br><br>Please point me out, where am I going wrong?</div></blockquote><div><br></div><div>The ::Pointer member is already a pointer, so there should be no need for the '*'. That is, change</div><div class="gmail_quote">
<br></div> ImageType::Pointer *itk_img_ptr = (ImageType::Pointer*)itk_img_void_ptr;</div><div class="gmail_quote"><br></div><div class="gmail_quote">to</div><div class="gmail_quote"><br></div><div class="gmail_quote"> ImageType::Pointer itk_img_ptr = (ImageType::Pointer)itk_img_void_ptr;<br clear="all">
<br></div><div class="gmail_quote">Here is a demo of ImageToVTKImageFilter<br><div><a href="http://www.itk.org/Wiki/ITK/Examples/ItkVtkGlue/ImageToVTKImageFilter">http://www.itk.org/Wiki/ITK/Examples/ItkVtkGlue/ImageToVTKImageFilter</a></div>
<div><br></div><div>I'm not sure I follow why you need your own function, isn't this conversion exactly what this filter does?</div><div><a href="http://www.itk.org/Wiki/ITK/Examples/ItkVtkGlue/ImageToVTKImageFilter"></a><div>
<br></div></div><div>David</div></div></div></div>