[Insight-users] SpatialObjectToImageFilter Exception

Kishore Mosaliganti kishoreraom at gmail.com
Thu Aug 19 19:15:12 EDT 2010


Hi Sebastian,

It looks like you did not set size[2] value.

Kishore

On Thu, Aug 19, 2010 at 12:25 PM, Sebastian Jameson
<jameson.sebastian at gmail.com> wrote:
> 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
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
>


More information about the Insight-users mailing list