int main( int argc, char *argv[] )
{
if( argc != 2 )
{
std::cerr << "Usage: " << argv[0] << " outputimagefile " << std::endl;
return EXIT_FAILURE;
}
typedef unsigned char PixelType;
const unsigned int Dimension = 3;
PolygonType, ImageType > SpatialObjectToImageFilterType;
SpatialObjectToImageFilterType::Pointer imageFilter =
SpatialObjectToImageFilterType::New();
ImageType::SizeType size;
size[ 0 ] = 100;
size[ 1 ] = 100;
size[ 2 ] = 1;
imageFilter->SetSize( size );
ImageType::SpacingType spacing;
spacing[0] = 100.0 / size[0];
spacing[1] = 100.0 / size[1];
spacing[2] = 1.0;
imageFilter->SetSpacing( spacing );
PolygonType::Pointer polygon = PolygonType::New();
const unsigned int numberOfPoints = 6;
PolygonType::PointType point;
PolygonType::PointType::VectorType radial;
radial[0] = 0.0;
radial[1] = 0.0;
radial[2] = 0.0;
PolygonType::PointType center;
center[0] = 50.0;
center[1] = 50.0;
center[2] = 0.0;
const double radius = 40.0;
for( unsigned int i=0; i < numberOfPoints; i++ )
{
const double angle = 2.0 *
vnl_math::pi * i / numberOfPoints;
radial[0] = radius * std::cos( angle );
radial[1] = radius * std::sin( angle );
point = center + radial;
polygon->AddPoint( point );
}
std::cout << "Polygon Perimeter = " << polygon->MeasurePerimeter() << std::endl;
std::cout << "Polygon Area = " << polygon->MeasureArea() << std::endl;
imageFilter->SetInput( polygon );
WriterType::Pointer writer = WriterType::New();
writer->SetFileName( argv[1] );
writer->SetInput( imageFilter->GetOutput() );
try
{
imageFilter->Update();
writer->Update();
}
{
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}