Hi,<br>I am using the ImportImageFilter to assign a datablock to an image. The problem I am facing is that when i return the output of this filter in a function, the image pointer apparently contains no data even though I have let the filter manage the data. I have included a small sample code. Is this a bug or am I missing something?<br>
Thanks,<br>Krishnan<br><br>/* ====================================================== */<br>#include "itkImageFileWriter.h"<br>#include "itkImportImageFilter.h"<br><br>typedef short PixelType;<br>int const Dims3D=3, Dims2D=2;<br>
typedef itk::Image<PixelType, Dims3D> ImageType3D;<br><br>ImageType3D::Pointer func(void)<br>{<br> typedef itk::ImportImageFilter<PixelType, Dims3D> Import_Filter_Type;<br> Import_Filter_Type::Pointer importFilter=Import_Filter_Type::New();<br>
Import_Filter_Type::SizeType size;<br> size[0] = 51;<br> size[1] = 51;<br> size[2] = 60;<br> Import_Filter_Type::IndexType start;<br> start.Fill(0);<br> Import_Filter_Type::RegionType region;<br> region.SetSize(size);<br>
region.SetIndex(start);<br> double Origin[Dims3D];<br> Origin[0]=Origin[1]=Origin[2]=0.0;<br> importFilter->SetRegion(region);<br> importFilter->SetOrigin(Origin);<br> Origin[0]=Origin[1]=Origin[2]=1.0;<br>
importFilter->SetSpacing(Origin);//Reuse; just for demo code<br> short *buf=new short[size[0]*size[1]*size[2]];<br> importFilter->SetImportPointer(buf,size[0]*size[1]*size[2], true);<br> try<br> {<br>
importFilter->Update();<br> }<br> catch(itk::ExceptionObject &ob)<br> {<br> std::cout<<ob<<std::endl;<br> getchar();<br> }<br> return importFilter->GetOutput();<br>
}<br>int main( int argc, char **argv)<br>{<br> typedef itk::ImageFileWriter<ImageType3D> WriterType;<br> WriterType::Pointer writer = WriterType::New();<br> ImageType3D::Pointer im = func();<br><br> writer->SetInput(im);<br>
writer->SetFileName("test.mhd");<br> try<br> {<br> writer->Update();<br> }<br> catch(itk::ExceptionObject &ob)<br> {<br> std::cout<<ob<<std::endl;<br> }<br> <br> return 0;<br>
}<br><br>