<div><div><div class="gmail_quote">On Fri, Oct 22, 2010 at 12:44 PM, Prathamesh Kulkarni <span dir="ltr">&lt;<a href="mailto:prathameshmkulkarni@gmail.com">prathameshmkulkarni@gmail.com</a>&gt;</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&#39;s output from the function which does the conversion. Following is a code snippet.<br>


<br>vtkSmartPointer&lt;vtkImageData&gt; convertITKImageToVTKImage(void *itk_img_void_ptr){<br>    typedef float PixelType;<br>    const unsigned int dimensions = 2;<br>    typedef itk::Image&lt;PixelType, dimensions&gt; 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-&gt;GetPointer();<br><br>    typedef itk::ImageToVTKImageFilter&lt;ImageType&gt; ITKToVTKFilterType;<br>


    ITKToVTKFilterType::Pointer ITK_to_VTK_filter = ITKToVTKFilterType::New();<br><br>    ITK_to_VTK_filter-&gt;SetInput(itk_img);<br>    ITK_to_VTK_filter-&gt;Update();<br><br>    vtkSmartPointer&lt;vtkImageData&gt; vtk_image = ITK_to_VTK_filter-&gt;GetOutput();<br>


    //vtk_image-&gt;Update();<br>    <br>    //uncomment to test.. THIS RENDERING WORKS<br>    renderImage(castImage(vtk_image, std::string(&quot;unsigned char&quot;)), true);<br><br>    return vtk_image;<br>}<br><br>void foo(){<br>


    vtkSmartPointer&lt;vtkImageData&gt; 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(&quot;unsigned char&quot;)), 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 &#39;*&#39;. 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&#39;m not sure I follow why you need your own function, isn&#39;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>