[Insight-users] SpatialObjectToImageFilter Crash - Why?

itkvtk123 at gmx.net itkvtk123 at gmx.net
Wed Oct 28 14:44:24 EDT 2009


I want to convert a polygon to an image.
The code mentioned below works fine in Debug mode, but crashes in Release mode. (VS 2005 Pro)

It works in Release mode, too, as long as I add only 2 or less points to the polygon.

I already had a look at Examples/Filtering/SpatialObjectToImage3.cxx, which works and which is exactly my problem, but I don't understand why my code doesn't work.
Setting up the image spacing and image size for both the spatial object and the filter did not solve the problem.


Minimal code:

#include "itkSpatialObjectToImageFilter.h"
#include "itkPolygonSpatialObject.h"

int main()
{
	typedef unsigned short PixelType;
	typedef itk::Image<PixelType, 2> Image2DType;

	typedef itk::PolygonSpatialObject<2> PolygonType;
	PolygonType::Pointer polygon = PolygonType::New();

	PolygonType::PointType polyPoint;
	polyPoint[0] = 0;
	polyPoint[1] = 0;
	polygon->AddPoint(polyPoint);
	polyPoint[0] = 500;
	polyPoint[1] = 200;
	polygon->AddPoint(polyPoint);
	polyPoint[0] = 0;
	polyPoint[1] = 200;
	polygon->AddPoint(polyPoint);

	typedef itk::SpatialObjectToImageFilter<PolygonType, Image2DType> SpatialToImageFilterType;
	SpatialToImageFilterType::Pointer spatialFilter = SpatialToImageFilterType::New();

	spatialFilter->SetInput(polygon);
	spatialFilter->Update(); // crashes here
}
-- 
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/chbrowser


More information about the Insight-users mailing list