[Insight-users] ImportImageFilter segfault repost.
Krishnan V
v.srikrishnan at gmail.com
Sat Jan 8 22:59:25 EST 2011
Reposting my earlier message.
====
Hi,
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?
Thanks,
Krishnan
/* ====================================================== */
#include "itkImageFileWriter.h"
#include "itkImportImageFilter.h"
typedef short PixelType;
int const Dims3D=3, Dims2D=2;
typedef itk::Image<PixelType, Dims3D> ImageType3D;
ImageType3D::Pointer func(void)
{
typedef itk::ImportImageFilter<PixelType, Dims3D> Import_Filter_Type;
Import_Filter_Type::Pointer importFilter=Import_Filter_Type::New();
Import_Filter_Type::SizeType size;
size[0] = 51;
size[1] = 51;
size[2] = 60;
Import_Filter_Type::IndexType start;
start.Fill(0);
Import_Filter_Type::RegionType region;
region.SetSize(size);
region.SetIndex(start);
double Origin[Dims3D];
Origin[0]=Origin[1]=Origin[2]=0.0;
importFilter->SetRegion(region);
importFilter->SetOrigin(Origin);
Origin[0]=Origin[1]=Origin[2]=1.0;
importFilter->SetSpacing(Origin);//Reuse; just for demo code
short *buf=new short[size[0]*size[1]*size[2]];
importFilter->SetImportPointer(buf,size[0]*size[1]*size[2], true);
try
{
importFilter->Update();
}
catch(itk::ExceptionObject &ob)
{
std::cout<<ob<<std::endl;
getchar();
}
return importFilter->GetOutput();
}
int main( int argc, char **argv)
{
typedef itk::ImageFileWriter<ImageType3D> WriterType;
WriterType::Pointer writer = WriterType::New();
ImageType3D::Pointer im = func();
writer->SetInput(im);
writer->SetFileName("test.mhd");
try
{
writer->Update();
}
catch(itk::ExceptionObject &ob)
{
std::cout<<ob<<std::endl;
}
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110109/7de02fc6/attachment.htm>
More information about the Insight-users
mailing list