int main( int argc, char *argv[] )
{
if( argc != 2 )
{
std::cerr << "Usage: " << argv[0] << " outputimagefile " << std::endl;
return EXIT_FAILURE;
}
using PixelType = unsigned char;
PolygonType, ImageType >;
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();
constexpr 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;
constexpr double radius = 40.0;
typename PolygonType::PolygonPointType polygonPoint;
for( unsigned int i=0; i < numberOfPoints; i++ )
{
radial[0] = radius * std::cos( angle );
radial[1] = radius * std::sin( angle );
point = center + radial;
polygonPoint.SetPositionInObjectSpace( point );
polygon->GetPoints().push_back( polygonPoint );
}
polygon->Update();
std::cout << "Polygon Perimeter = "
<< polygon->MeasurePerimeterInObjectSpace() << std::endl;
std::cout << "Polygon Area = "
<< polygon->MeasureAreaInObjectSpace() << 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;
}