int main( int argc, char *argv[] )
{
if( argc != 2 )
{
std::cerr << "Usage: " << argv[0] << " outputimagefile " << std::endl;
return EXIT_FAILURE;
}
typedef unsigned char PixelType;
PolygonType, ImageType > SpatialObjectToImageFilterType;
SpatialObjectToImageFilterType::Pointer imageFilter =
SpatialObjectToImageFilterType::New();
size[ 0 ] = 100;
size[ 1 ] = 100;
size[ 2 ] = 1;
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;
radial[0] = 0.0;
radial[1] = 0.0;
radial[2] = 0.0;
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++ )
{
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;
}