[Insight-users] SpatialObjectToImageFilter Exception

Sebastian Jameson jameson.sebastian at gmail.com
Thu Aug 19 12:25:42 EDT 2010


Hi,

I'm trying to build an image with spatial objects but whenever I use the
SpatialObjectToImageFilter an Exception gets thrown:

ERROR: ExceptionObject caught !

itk::ExceptionObject (0x7f70a0000ca0)
Location: "TElement* itk::ImportImageContainer<TElementIdentifier,
TElement>::AllocateElements(TElementIdentifier) const [with
TElementIdentifier = long unsigned int, TElement = short unsigned int]"
File: /itk/InsightToolkit-3.20.0/Code/Common/itkImportImageContainer.txx
Line: 188
Description: Failed to allocate memory for image.


Here is my code:


  try
    {

    typedef itk::ArrowSpatialObject<3>   ArrowType;
    ArrowType::Pointer myArrow = ArrowType::New();
    myArrow->SetLength(20);

    ArrowType::VectorType direction;
    direction.Fill(0);
    direction[1] = 1.0;
    myArrow->SetDirection(direction);

    typedef itk::Image< unsigned short, 3 > ImageType;
    typedef itk::SpatialObjectToImageFilter< ArrowType, ImageType >
SpatialObjectToImageFilterType;

    SpatialObjectToImageFilterType::Pointer imageFilter =
SpatialObjectToImageFilterType::New();
    imageFilter->SetInput(myArrow);

    ImageType::SizeType size;
    size[ 0 ] = 200;
    size[ 1 ] = 200;
    imageFilter->SetSize( size );
    ImageType::SpacingType spacing;
    spacing[0]=1;
    spacing[1]=1;
    spacing[2]=1;
    imageFilter->SetSpacing(spacing);
    imageFilter->Update();

    typedef itk::ImageFileWriter< ImageType >  WriterType;
    WriterType::Pointer writer = WriterType::New();
    char * output_name="/tmp/arrow.nrrd" ;
    writer->SetFileName( output_name);
    writer->SetInput( imageFilter->GetOutput() );

    std::cout << "Writing image: " << output_name << std::endl;
    writer->Update();
    }
  catch( itk::ExceptionObject & err )
    {
    std::cerr << "ERROR: ExceptionObject caught !" << std::endl;
    std::cerr << err << std::endl;
    }

  return EXIT_SUCCESS;

What am I doing wrong?

Thanks for the help,
seb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100819/feb275bc/attachment.htm>


More information about the Insight-users mailing list